SQL Server 中几种索引的简单理解

本文详细介绍了数据库中主键的概念及其使用方法,并对聚焦索引与非聚焦索引进行了对比解析,包括创建与删除索引的具体SQL语法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主键(Primary Key):主键在一个表中可以有多个,但是主键的内容不能为空。

create table 表名 (    字段名1 int not null,    …………,
   [constraint 约束名] primary key (字段名1, …)
 )

alter table 表名 [add constraint 约束名] primary key(字段名1 ,… )

ALTER TABLE 表名DROP CONSTRAINT 约束名

 

聚焦索引:表的物理存储顺序与指针(即逻辑)顺序相同,一张表存在的聚焦索引不能超过1个。形如:按字典的字母排序查找生字;

create clustered index index_name on table_name(column asc,)

create unique clustered index index_name on table_name(column asc,) //唯一聚集索引

drop  index index_name on table_name with (online=off)

 

非聚集索引:物理与逻辑顺序不同,一张表可以存在多个非聚集索引。形如:字典按部首查找生字。

 

create nonclustered index index_name on table_name(column asc,)


drop  index index_name on table_name with (online=off)

 

 

 

转载于:https://www.cnblogs.com/Janzen/p/5985261.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值