开发者

Limited no of records in table SQLite

Q 1) I want to insert limited number of records in my db table lets say 10. If i add 11th record then oldest record will be deleted & 11th record will be added as new record.

How can i know which is the oldest record in my table , so that i can delete it & add new record.

Q 2) I want to insert maximum 2 records in my table. My first record is default record. If user doesn't provide second record then i will use my default record. My second record is changeable. User entered second record. Now if user want to change second record how can i change it?

sql = "update abc set name = ? where id = ?" ,newName,existingId

Like above query? 开发者_如何转开发But how can i know existingId in this case?


First: add a date field with default value NOW() and then delete from mytable where date=min(date) or sth like that. But you'd better use some other routine than sqlite.

Second: if you've got only two rows and want to change them, you can, surely, hardcode your ids, but it would be an ugly solution. You can use config files or sth like that, or add boolean column default to the table and distinguish them by its value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜