34,590
社区成员
发帖
与我相关
我的任务
分享
CREATE TABLE [dbo].[a](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NULL,
CONSTRAINT [PK_a] PRIMARY KEY CLUSTERED
(
[id] ASC
)
)
CREATE UNIQUE NONCLUSTERED INDEX [IX_a] ON [dbo].[a]
(
[name] ASC
)
GO
insert a(name)
select 'd'
union all
select 'c'
union all
select 'b'
union all
select 'a'
select * from a
select * from a
order by id
/*
id name
1 d
2 c
3 b
4 a
*/
select * from a
--通过查询提示,强制使用聚集索引PK_a
select * from a with(index (PK_a))
CREATE TABLE [dbo].[a](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](50) NULL,
CONSTRAINT [PK_a] PRIMARY KEY CLUSTERED
(
[id] ASC
)
)
CREATE UNIQUE NONCLUSTERED INDEX [IX_a] ON [dbo].[a]
(
id ASC
)
GO
insert a(name)
select 'd'
union all
select 'c'
union all
select 'b'
union all
select 'a'
select * from a
/*
id name
----------- --------------------------------------------------
1 d
2 c
3 b
4 a
*/