tags:

views:

18

answers:

1

In MS SQL I would use

SET IDENTITY INSERT ON

How do I do something similar in SQLite. I am trying to upgrade a database and want to maintain the IDs from the original

Thanks

+3  A: 

You don't need to set IDENTITY INSERT, because it is always possible to set the value explicitly. With SQLite, you can just insert into the ROWID column:

drop table test;
create table test(name varchar);
insert into test(name) values('Hello');
insert into test(rowid, name) values(10, 'World');
select rowid, name from test;

The same if you use an autoincrement primary key:

drop table test;
create table test(id integer primary key autoincrement, name varchar);
insert into test(name) values('Hello');
insert into test values(10, 'World');
select * from test;

See also http://www.sqlite.org/autoinc.html

Thomas Mueller
Great thanks, Im using System.Data.Sqlite for use with Entity Framework in c# therefore it is generating the sql for me, it must not be including that column! Arse!
tigermain