SET NOCOUNT OFF USE pubs IF EXISTS (SELECT name FROM sysindexes WHERE name = 'au_id_ind') DROP INDEX authors.au_id_ind GO USE pubs CREATE INDEX au_id_ind ON authors (au_id) GO
select identity(int,1,1) as idd,* into #t from test select * from test where idd=10 但是有服务器: 消息 207,级别 16,状态 3,行 1 列名 'idd' 无效。
统计行数: select count(*) from 表
取第10条记录 select myid=identity(int,1,1),* into #tb from test select * from #tb where myid=10
to zjcxc(邹建) select myid=identity(int,1,1),* into #tb from test select * from #tb where myid=10 可以说说这样sql语句是怎样理解吗?
创建一个与原表记录相同,包含记录号(用标识字段来实现)的临时表 select myid=identity(int,1,1),* into #tb from test--查询记录号为10的记录 select * from #tb where myid=10--查询结束后,最好加上删除临时表的语句 drop table #tb
如果该表有关键字段,则象下面这样写: Select * from yourTable a where (select count(*) from yourTable where KeyField <= a.KeyField) = 10 KeyField是你的表的关键字段的名称 yourtable是表名 如果该表没有关键字段,则想下面这样写: Select identity(int,1,1) as id,* into #temp from yourTable Select * from #temp where id = 10 drop table #temp
USE pubs
IF EXISTS (SELECT name FROM sysindexes
WHERE name = 'au_id_ind')
DROP INDEX authors.au_id_ind
GO
USE pubs
CREATE INDEX au_id_ind
ON authors (au_id)
GO
select * from test where idd=10
但是有服务器: 消息 207,级别 16,状态 3,行 1
列名 'idd' 无效。
select count(*) from 表
select myid=identity(int,1,1),* into #tb from test
select * from #tb where myid=10
select myid=identity(int,1,1),* into #tb from test
select * from #tb where myid=10
可以说说这样sql语句是怎样理解吗?
select myid=identity(int,1,1),* into #tb from test--查询记录号为10的记录
select * from #tb where myid=10--查询结束后,最好加上删除临时表的语句
drop table #tb
Select * from yourTable a
where (select count(*) from yourTable where KeyField <= a.KeyField) = 10
KeyField是你的表的关键字段的名称 yourtable是表名
如果该表没有关键字段,则想下面这样写:
Select identity(int,1,1) as id,* into #temp from yourTable
Select * from #temp where id = 10
drop table #temp