34,590
社区成员
发帖
与我相关
我的任务
分享
if object_id('[ta]') is not null drop table [ta]
go
create table [ta]([ID] uniqueidentifier not null default newid(),[graNO] varchar(10),[graName] varchar(10),[FID] int NOT NULL)
--1.创建聚集索引:
create unique clustered index idx_ta_id on ta(FID)
--2.创建主键:
alter table ta add constraint pk_ta_id primary key (ID)
--3.查询索引
sp_helpindex ta
/*
index_name index_description index_keys
----------- --------------------------------------------- ------------
idx_ta_id clustered, unique located on PRIMARY FID --在FID上的才是聚集索引
pk_ta_id nonclustered, unique, primary key located on PRIMARY ID --ID已经是非聚集索引
*/
--4.插入测试数据
insert [ta]([graNO],[graName],[FID])
select 's1101','vb',1 union all
select 's1101','c',2
--5.查询
select * from ta
/*
ID graNO graName FID
------------------------------------ ---------- ---------- -----------
F0814E78-25AA-4ADE-944F-64227EB16485 s1101 vb 1
4DACCE91-8AB5-4983-9E0C-359F896D5078 s1101 c 2
(2 行受影响)
*/