Hi all,

I did  look at archives and found one way to do this:

bash:~$ sqlite3 test.db
SQLite version 3.2.8
Enter ".help" for instructions
sqlite> create table test("ID" INTEGER NOT NULL, "a" VARCHAR(100), "b" 
VARCHAR(100), PRIMARY KEY("ID","b"));
sqlite> insert into test ("a","b") VALUES ('foo', 'bar');
SQL error: test.ID may not be NULL
sqlite> insert into test ("ID","a","b") VALUES ((select max(ID) from 
test)+1,'foo', 'bar');
SQL error: test.ID may not be NULL
sqlite> select max(ID) from test;

sqlite> insert into test ("ID","a","b") VALUES (1,'foo', 'bar');
sqlite> select max(id) from test;
1
sqlite> insert into test ("ID","a","b") VALUES ((select max(id) from 
test)+1,'baz', 'qux');
sqlite> select * from test;
1|foo|bar
2|doo|baz
sqlite> 


I've read on sqlite.org that there's a bug preventing autoincrement to
work on multiple column primary keys defined tables that is retained for
compatibility issues. (Actually regarding a PRIMARY KEY DESC as written
here: http://www.sqlite.org/lang_createtable.html#rowid ).

I'm still wondering if this is the right way to handle such cases of if
there's a better way.

Also: couldn't that bug be resolved for multi-column primary key situations
if only one column is of type "INTEGER" (vs "VARCHAR" or even "INT")?
Just wondering.. I'm new to sqlite and not an expert sql-hacker for the
same matter.

Thanks for any insights!

Chris
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to