--转贴 --------------------------------------------------- --最后N条记录 --如果你的表中无任何字段可以判断记录的先后顺序,就用:declare @r int select * into #t from a set @r=@@rowcount-100 --100就是你的N set rowcount @r delete from #t set rowcount 0 select * from #tdrop table #t
建立存储过程 : CREATE PROCEDURE findint AS truncate table temptable SELECT identity(int,1,1) FID,name,code,id into into #temp from youtab order by id ascinsert temptable SELECT name,code,id FROM #temp where FID<=20 drop table #temp select * from temptable
select top 20 * from 表名 order by 字段(如id) desc
---------------------------------------------------
--最后N条记录
--如果你的表中无任何字段可以判断记录的先后顺序,就用:declare @r int
select * into #t from a
set @r=@@rowcount-100 --100就是你的N
set rowcount @r
delete from #t
set rowcount 0
select * from #tdrop table #t
CREATE PROCEDURE findint
AS
truncate table temptable
SELECT identity(int,1,1) FID,name,code,id into into #temp from youtab order by id ascinsert temptable SELECT name,code,id FROM #temp where FID<=20
drop table #temp
select * from temptable