dbTalk Databases Forums  

Last record in a Table

microsoft.public.sqlserver.mseq microsoft.public.sqlserver.mseq


Discuss Last record in a Table in the microsoft.public.sqlserver.mseq forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Senthilkumar
 
Posts: n/a

Default Last record in a Table - 07-14-2003 , 11:31 PM






I want to update the last row in a table. How do I do it?
Thanks in advance

Reply With Quote
  #2  
Old   
Vishal Parkar
 
Posts: n/a

Default Re: Last record in a Table - 07-15-2003 , 02:27 PM






How do you define "last row" in a table? do you have any identification to
each row so that you can pick up the "last row" of the table? SQL server
internally doesn't maintain any identification so that you can straight away
define last row. You may have to add a column to the table definition with a
default value as "getdate()" by which you can identifiy last inserted row
into the table. OR a unique column in the table with the incremental
serially generated value (identity) for the column which will allow you to
define the "last row" of the table.
Ex:

create table #t (idd int, created datetime default getdate())
insert into #t(idd) values(1)
go
insert into #t(idd) values(2)
go
insert into #t(idd) values(3)
go

With the above table definition you can find out last row on the basis
of "created" column as

select * from #t where created in
(select max(created) from #t)

you can find last row on the basis of column "idd" as

select * from #t where idd in
(select max(idd) from #t)

--
-Vishal
Senthilkumar <luckysenthil (AT) hotmail (DOT) com> wrote

Quote:
I want to update the last row in a table. How do I do it?
Thanks in advance



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.