On Feb 6, 2005, at 1:35 AM, [EMAIL PROTECTED] wrote:
Randall Randall <[EMAIL PROTECTED]> writes:
sqlite> create table package (rowid integer primary key autoincrement, name
text);
SQL error: near "autoincrement": syntax error


What am I doing wrong, here?

You're putting in the word "autoincrement". Also, "rowid" is a special word
in SQLite and should not generally be used as a column name.


In SQLite, integer primary keys will autoincrement if you insert a NULL value
into that field, either explicitly or implicitly (by inserting nothing into
that column):


sqlite> CREATE TABLE package
sqlite> (
sqlite>   id    INTEGER PRIMARY KEY,
sqlite>   name  TEXT
sqlite> );

sqlite> INSERT INTO package (id, name) VALUES (NULL, 'first row');
sqlite> INSERT INTO package (name) VALUES ('second row');

sqlite> .mode line
sqlite> SELECT * from package;

   id = 1
 name = first row

   id = 2
 name = second row

Yes, but using this means that deleted row ids can get reused, while using the "autoincrement" keyword specifically is supposed to make new row ids larger than any previously used row id, whether it's still around or not. I need this because my application implements an undo feature which may need to re-insert a specific row id after deletion.

However, this:
Also, "rowid" is a special word
in SQLite and should not generally be used as a column name.

brings up an interesting point. Is it really likely to cause problems to use "rowid" here? If so, how can I get the "autoincrement" behavior with the normal rowid (as opposed to the "primary key" behavior you describe above)?

In any case, Will Leshner points out that the autoincrement
keyword is only supported in 3.1 and up, so I'll move along
now. :)

Thanks!

--
Randall Randall <[EMAIL PROTECTED]>
Property law should use #'EQ , not #'EQUAL .



Reply via email to