On May 27, 2014, at 8:11 PM, Drago, William @ MWG - NARDAEAST 
<william.dr...@l-3com.com> wrote:

> Is there any difference between using REPLACE as opposed to deleting records 
> and then inserting new ones to take their place?

Same difference. 

For example:

create table foo
(
  id  integer primary key not null,
  key text not null,

  constraint foo_uk unique( key )
);

sqlite> insert or replace into foo( key ) values( 'a' );
sqlite> select * from foo;
1|a
sqlite> insert or replace into foo( key ) values( 'a' );
sqlite> select * from foo;
2|a
sqlite> insert or replace into foo( key ) values( 'a' );
sqlite> select * from foo;
3|a

Note how the primary key, id, had changed over time, from 1 to 3.

For all practical purposes, REPLACE is useless, if not dangerous even.

What would really be useful would be a MERGE operation instead:

http://en.wikipedia.org/wiki/Merge_%28SQL%29
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to