create table #(ID int) insert # select 1 union all select 3 union all select 2 union all select 5 union all select 4 select * from # /* ID ----------- 1 3 2 5 4(5 個資料列受到影響) */--建索引 create index IX_# on #(ID)select * from # /* ID ----------- 1 2 3 4 5(5 個資料列受到影響) */
set nocount on if object_id('test')is not null drop table test go create table test (ID int ,[name] varchar(5)) insert test select 1,'A' insert test select 3,'B' insert test select 2,'C' insert test select 5,'D' insert test select 4,'E' select * from test create clustered index Intest on test(id) go select * from test /* ID name ----------- ----- 1 A 3 B 2 C 5 D 4 EID name ----------- ----- 1 A 2 C 3 B 4 E 5 D*/
--?
order by id
insert #
select 1 union all
select 3 union all
select 2 union all
select 5 union all
select 4
select * from #
/*
ID
-----------
1
3
2
5
4(5 個資料列受到影響)
*/--建索引
create index IX_# on #(ID)select * from #
/*
ID
-----------
1
2
3
4
5(5 個資料列受到影響)
*/
if object_id('test')is not null drop table test
go
create table test (ID int ,[name] varchar(5))
insert test select 1,'A'
insert test select 3,'B'
insert test select 2,'C'
insert test select 5,'D'
insert test select 4,'E'
select * from test
create clustered index Intest on test(id)
go
select * from test
/*
ID name
----------- -----
1 A
3 B
2 C
5 D
4 EID name
----------- -----
1 A
2 C
3 B
4 E
5 D*/