On 6/16/08, Gregor Brandt <[EMAIL PROTECTED]> wrote:
> Sorry about this, but this is a SQL question and not a SQLite specific
>  question.
>
>  Is there a way to increment a value in a table in-situ.   Without
>  reading it, incrementing it, writing it?
>
>  I need to insert an entry into a table, it has an id, all entries with
>  id's >= the id need to be incremented to keep the id's unique
>
>  ie
>
>  1 bob
>  2 joe
>  3 irene
>
>  someone wants to insert 2 sarah, I need the table to look like this

-- to keep track of the id that is going to be duplicated
UPDATE table
SET id = -1
WHERE id = 2


INSERT INTO table VALUES (2, 'sarah');

>
>  1 bob
>  2 sarah
>  3 joe
>  4 irene
>

UPDATE table
SET id = id + 1
WHERE id > 2 OR id = -1



>
>  Any help would be great.
>  thanks
>
>  -----------------------------------------------------------------
>  Gregor
>
>
>  _______________________________________________
>  sqlite-users mailing list
>  sqlite-users@sqlite.org
>  http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>


-- 
Puneet Kishor
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to