On 10 Jan 2012, at 7:23am, Durga D wrote: > create table if not exists emp(id integer primary key autoincrement, > col1 text, col2 text, unique (col1, col2)); > > here, col1 and col2 should be unique. I tried to insert 10000000 records > with unique(col1, col2). It's very slow. So, I choosed id as primary key > (surrogate key) and without unique key. > > create table if not exists emp(id integer primary key autoincrement, col1 > text, col2 text); > > I want to insert a record if not exists. How?
You did it correctly the first time. That is the correct way to prevent duplicates. Your test is unrealistic and will not reflect how fast the database will be in real life (are you really going to have your application insert 10,000,000 rows often ?) but if you really do want to do this, put all your insert commands into a transaction: BEGIN TRANSACTION; insert ...; insert ...; insert ...; ...; END TRANSACTION; Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users