----- Forwarded by Ben Carlyle/AU/IRSA/Rail on 09/03/2004 10:56 AM -----
Ben Carlyle
09/03/2004 10:54 AM
To: "Roger Hawkins" <[EMAIL PROTECTED]>@CORP
cc:
Subject: RE: [sqlite] Resetting primary key auto-increment after table
re-create
Roger,
"Roger Hawkins" <[EMAIL PROTECTED]>
08/03/2004 03:18 PM
To: <[EMAIL PROTECTED]>
cc:
Subject: RE: [sqlite] Resetting primary key auto-increment after table
re-create
> Thanks for your reply...
> I havent found any reference to this in the doco so Im not sure how any
> of this might work..
http://sqlite.org/faq.html#q1
Pay particular attention to the "is logically equivalent" part.
> So what you are saying is that if I recreate the table I can insert all
> the old values back into the newly created table (including the primary
> key values) and the primary key column wont complain? That's a bit
> scary!
So long as you don't insert the same number into the INTEGER PRIMARY KEY
twice, sqlite will not complain. It's a primarily a primary key. It only
doubles as an auto-increment field when you insert NULLs into it.
> Even if this is true what happens when I next insert a value (normally
> without specifying the primary key field) - does it just pick up the
> latest?
> Any one tried this?
Yes. You can, too:
CREATE TABLE foo(bar INTEGER PRIMARY KEY);
INSERT INTO foo VALUES(NULL);
INSERT INTO foo VALUES(2);
INSERT INTO foo VALUES(NULL);
INSERT INTO foo VALUES(3); -- SQL Error: PRIMARY KEY must be unique
SELECT * FROM foo:
1
2
3
Benjamin.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]