On 19 Nov 2017, at 8:37pm, Shane Dev <devshan...@gmail.com> wrote:

> sqlite> select * from fruit;
> id|name
> 1|apple
> 2|pear
> 3|kiwi
> 
> Is there an easy way to insert 'banana' between apple and pear while still
> maintaining a consistent order of the ID field?
> 
> desired result -
> 
> sqlite> select * from fruit;
> 1|apple
> 2|banana
> 3|pear
> 4|kiwi

UPDATE fruit SET id = id+1 WHERE id >=2;
INSERT …

But the real question you need to ask yourself is why you’re doing this.  ID 
numbers in a table are meant to be seen by computers, never humans.  Why does 
an ID number matter to you ?  Why aren’t you just inserting your new fruit 
after the end of the exiting fruits ?

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to