Question:
How to insert row when one column is auto increment sql?
?
2011-11-19 15:58:30 UTC
I have a data base that has the columns:
rowid, data1, data2, data3

rowid is set to int auto increment

when I insert a row I want the rowid to auto increment - I am using the following to insert a row:

INSERT INTO MYTABLE VALUES(NULL, dataA, dataB, dataC);

My question is, is using a value of NULL for the rowid position correct? If not, what is usually put there?
Three answers:
djbckr
2011-11-19 16:15:26 UTC
When programming SQL, it's best to be explicit in EVERYTHING. Try this:



insert into mytable (data1, data2, data3) values (dataA, dataB, dataC);



Since rowid is autoincrement, don't specify it in the field list.



BTW, I might steer clear of a column called rowid. I'm sure you are using something other than Oracle, but if you decide to use it, rowid is a reserved column name and keyword.
2015-08-13 19:56:08 UTC
This Site Might Help You.



RE:

How to insert row when one column is auto increment sql?

I have a data base that has the columns:

rowid, data1, data2, data3



rowid is set to int auto increment



when I insert a row I want the rowid to auto increment - I am using the following to insert a row:



INSERT INTO MYTABLE VALUES(NULL, dataA, dataB, dataC);



My question is, is using a...
2016-03-19 03:15:58 UTC
this should do it for you: id -> your primary key field select id from table order by id desc limit 1


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...