1
declare @PageSize int--每页的大小(行数)
2
declare @PageCurrent int --要显示的页 从1开始
3
set @PageSize=10
4
set @PageCurrent=11
5
create table test(
6
[id][int]IDENTITY (1, 1)not null,
7
[name][varchar](10)null,
8
[age][int]null
9
) ON [PRIMARY]
10
go
11
select * from test
12
declare @n int
13
set @n=1
14
while(@n<=100000)
15
begin
16
insert into test values('n'+cast(@n as varchar),@n)
17
set @n=@n+1
18
end
19
select * from test
20
21
--method1:use not in
22
declare @nn int
23
set @nn = @PageSize*(@PageCurrent-1)
24
declare @str varchar(1000)
25
set @str='select top '+cast(@PageSize as varchar)+'* from test where id not in(select top '+cast(@nn as varchar)+' id from test)'
26
--method2:use >id
27
set @nn = @PageSize*(@PageCurrent-1)
28
declare @str varchar(1000)
29
set @str='select top '+cast(@PageSize as varchar)+'* from test where id>((select max(id) from (select top '+cast(@nn as varchar)+' id from test ) as m))'
30
-------------------------------------------------------
31
/*如果表没有标识列,则加个标识列*/
32
-------------------------------------------------------
33
--method1
34
alter table test
35
add id int identity(1,1)
36
--中间操作和上面一样
37
38
--update test set id=''
39
Alter table test Drop column id
40
41
--method2
42
select * into #temp from test
43
alter table #temp
44
add tel varchar(20) null
45
46
declare @PageSize int--每页的大小(行数) 2
declare @PageCurrent int --要显示的页 从1开始 3
set @PageSize=104
set @PageCurrent=115
create table test(6
[id][int]IDENTITY (1, 1)not null,7
[name][varchar](10)null,8
[age][int]null9
) ON [PRIMARY]10
go11
select * from test12
declare @n int13
set @n=114
while(@n<=100000)15
begin16
insert into test values('n'+cast(@n as varchar),@n)17
set @n=@n+118
end19
select * from test20

21
--method1:use not in22
declare @nn int23
set @nn = @PageSize*(@PageCurrent-1)24
declare @str varchar(1000)25
set @str='select top '+cast(@PageSize as varchar)+'* from test where id not in(select top '+cast(@nn as varchar)+' id from test)' 26
--method2:use >id27
set @nn = @PageSize*(@PageCurrent-1)28
declare @str varchar(1000)29
set @str='select top '+cast(@PageSize as varchar)+'* from test where id>((select max(id) from (select top '+cast(@nn as varchar)+' id from test ) as m))'30
-------------------------------------------------------31
/*如果表没有标识列,则加个标识列*/32
-------------------------------------------------------33
--method1 34
alter table test35
add id int identity(1,1)36
--中间操作和上面一样37

38
--update test set id=''39
Alter table test Drop column id40

41
--method242
select * into #temp from test 43
alter table #temp44
add tel varchar(20) null45

46


浙公网安备 33010602011771号