PySQLite and Autoincrement Keys

Gerhard Häring gh at ghaering.de
Mon May 26 05:18:38 EDT 2003


achrist at easystreet.com wrote:
> If I have a table with an autoincrement key in SQLite, and if I
> delete the row with the largets key, then add a new row, will or
> might the key value be re-used? 

You could have easily checked that for yourself, haven't you?

I just tested it and it seems ids are being reused.

> Is this good or bad? 

This depends. Mostly bad IMO, because you don't get the behaviour of 
SEQUENCEs in other RDBMS that way.

Also SQLite doesn't support any foreign keys, so you'd have to work 
around this limitation by multiple column CHECK CONSTRAINTs. I'm not 
sure if that's really feasible, as I've never done it myself.

Oh well :-(

[http://sqlite.org/lang.html]
"""
[...] CHECK constraints are ignored in the current implementation. [...]
"""

> Does the
> python DBAPI say anything about this?

No.

-- Gerhard





More information about the Python-list mailing list