I understand now. 

How does sqlite insert a record ? More specifically how does sqlite update the 
B-tree with the new record . Is there a linkage made between the newly inserted 
record and the previous one ?
Sent from BlackBerry® on Airtel

-----Original Message-----
From: Simon Slavin <slav...@bigfraud.org>
Sender: sqlite-users-boun...@sqlite.org
Date: Mon, 22 Aug 2011 17:32:51 
To: General Discussion of SQLite Database<sqlite-users@sqlite.org>
Reply-To: General Discussion of SQLite Database <sqlite-users@sqlite.org>
Subject: Re: [sqlite] EXT :Re:  Last record in db


On 22 Aug 2011, at 5:13pm, Igor Tandetnik wrote:

> On 8/22/2011 9:52 AM, Black, Michael (IS) wrote:
>> No...if you use autoincrement you can guarantee that "last" will be the last 
>> record inserted.
> 
> There's no contradiction. "Last" is still defined only for ordered sets 
> - you just chose a particular ordering, by rowid.

And even if you do that, it's easy to break the expected ordering:

> .schema t1
CREATE TABLE t1(id INT,data TEXT);

> select * from t1 ; 
id          data      
----------  ----------
1           one       
2           two       
3           tre 

> delete from t1 where data = 'two';

> insert into t1 (it, data) values (2, 'second');

Now the 'last' record is not the one with the highest value in the id column.

Igor is right.  The question from the original poster doesn't mean anything in 
SQL.  SQL has no concept of an order for rows, so it has no idea which row is 
'first' or 'last'.  If you, the programmer have your own idea what is first or 
last, write your own numbers into the database.

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

Reply via email to