0

I have tried it on android and it seems that simply ignores the given value assigned to the id field and just assigns it an autoincremented value (default behaviour).

Is there anyway to do this? I wanna do something like insert into table(id,name) values (100,"my name"). And let sqlite insert a row with id=100 not id=1 when the table is empty.

Thanks in advance.

Notbad
  • 5,936
  • 12
  • 54
  • 100
  • Check this post http://stackoverflow.com/questions/692856/set-start-value-for-autoincrement-in-sqlite/692871#692871 – Vishal Vyas Sep 25 '12 at 11:46
  • That works for me. You can set the id manually but it will increment the index counter to at least that id. So data inserted afterwards without explicit id will start at 101 for example. – zapl Sep 25 '12 at 11:47

1 Answers1

2

When you specify a value for a column, that value is used. (See the documentation.)

And for me, it works:

> CREATE TABLE t(id INTEGER PRIMARY KEY);
> INSERT INTO t VALUES(NULL);
> INSERT INTO t VALUES(123);
> INSERT INTO t VALUES(NULL);
> SELECT * FROM t;
1
123
124
CL.
  • 173,858
  • 17
  • 217
  • 259