Retrieving last record from the table in sql2000 | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Retrieving last record from the table in sql2000

How can I get the last record from a table without using any field of the table plz tell me immedeately as possible g.ramarao
How do you define last record?
Why do you want to do this?
Madhivanan Failing to plan is Planning to fail
hi Ramarao,
select @@identity(‘tablename’) will return the last inserted value. Regards.
hsGoswami
[email protected]
quote:Originally posted by ghemant hi Ramarao,
select @@identity(‘tablename’) will return the last inserted value. Regards.
hsGoswami
[email protected]

Thats not the correct syntax
That should be select ident_current(‘tableName’)
What happens if there is no identity column for that table?
Madhivanan Failing to plan is Planning to fail
using Magic Inserted table this can be achieved even if theirs no IDENTITY COLUMN. Regards. hsGoswami
[email protected]
The inserted and deleted tables can only be queried inside a trigger. Madhivanan’s questions are still valid.
Please define "last record". —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)

Assumption : <br />1. theirs a primary key field(tid which is primary key field ) in the tableA<br /><br />please run the query as :<br /><br />select * from tableA where tid = (select max(tid) from tableA)<br /><br /><br />[<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br />Regards.<br /><br /><br /><br />hsGoswami<br />[email protected]
quote:
How can I get the last record from a table without using any field of the table plz tell me immedeately as possible

You CANNOT get the last record from a table without using any field of the table. There is not a row order in SQL Server. Without the use of a field in the table, it’s impossible to find the last record. It is also impossible to know what the last record of a table is without defining it.
If you are just wanting to track inserts, you could use a trace or Profiler; however, again this is not necessarily a "last record" depending on the definition needed. MeanOldDBA
[email protected] When life gives you a lemon, fire the DBA.
I am agree with derrickleggett, because you can’t have data without field. When you have field and combination of all field form an row. So to calculate last row you need use field. Thanks & Regards Ravi K
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by RamaRao</i><br /><br />How can I get the last record from a table without using any field of the table plz tell me immedeately as possible<br />g.ramarao<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />Hi ramrao, i feel this will satisfy ur query but not others even im not adopting this.<br />Thru EM right click open table to select return all rows. after that right click on opened table pointer to goto the last row.[<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br />
]]>