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 |