Andreas Ntaflos wrote:
> 
> But it seems I misunderstood the point of AUTOINCREMENT. I am looking for 
> something like PostgreSQL's SERIAL data type [1] so when creating new rooms I 
> don't have to manually specify the roomID. Instead the next possible roomID 
> should be chosen automatically when INSERTing.
> 
> What is the correct SQLite-way of doing this?
> 

Well you could use a select to find the largest roomID the already 
exists in the building you are inserting into.

   insert into room values (
     (select max(roomID) from room
     where buildingID = :theBuilding) + 1,
     :theBuilding);

Now you only need to specify the building and sqlite will calculate the 
lowest unused room number in that building.

HTH
Dennis Cote
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to