I don't really advise using the rowid for this. Using the rowid is rather limiting, as it is not under your control. If you later need to change the ordering in some respect, you'll have to modify your database. You can do that, of course, but it's unnecessary pain. You did say you wanted to be able to insert at the beginning?
But even worse, the actual behavior may not be what you expect or want. It is not necessarily increasing, especially if you ever delete records. See the SQLite documentation for details: http://www.sqlite.org/autoinc.html If you declare your own primary key as MYSEQ INTEGER PRIMARY, then MYSEQ will become an alias for the rowid under the hood, so you will be just as efficient. If you then supply your own values for MYSEQ, the ordering will be under your control. It is interesting that both Mark and Marcin refer to "modern databases". "Modern" here means "Not designed with magnetic tape as the storage medium", or "since the mid 1970's". Even then, inserting records at the beginning required that you maintain your own idea of "beginning" and start your actual data somewhere in the middle of the tape. Even today, very few filesystems allow you to add data at the start of a file! On Jan 11, 7:36 am, Serdel <[email protected]> wrote: > Thanks for your answers. I was suggested a easier solution by sorting > the list by rowid so i do not need to add another column. > > On 11 Sty, 13:37, Marcin Orlowski <[email protected]> wrote: > > On 11 January 2011 13:10, Serdel <[email protected]> wrote: > > > > I am wondering how can I insert an element at the beginning of the > > > data base? > > > There's no such thing like "beginning of database". Database is set of data. > > Order of data is irrelevant to database itself. If you want to ensure > > certain order just sort your data. Or add numeric sequence (index), store > > record creation date etc etc > > > > I was searching for a solution but I am starting to wonder I have any > > > control of how the element are inserted. > > > No. There's no point to have anything like that exposed. You seem > > to miss basics of modern databases. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

