On 10/15/16 12:15 PM, Simon Slavin wrote:
On 14 Oct 2016, at 2:29pm, Thom Wharton <twhar...@northpointdefense.com> wrote:

I want to be able to programmatically insert a new record anywhere in that 
table. Let's suppose I want to create a new record between the records whose ID 
are 2 and 3.  This new record would need to take the ID of 3, and all 
subsequent records would need to have their primary keys updated.

Is there a way to do this automagically (like a specialized INSERT command?) in 
It's a silly thing to want to do since it makes a nonsense of what IDs are for. 
 I think you need to rethink what you're trying to do by changing existing IDs.

However, if you really need to do it ...

UPDATE MyTable SET ID = ID + 1 WHERE ID >= 3;


And, if any other table refers to records in that table via that ID field, THEY need to be changed too, all in an 'atomic' transaction.

Richard Damon

sqlite-users mailing list

Reply via email to