常用的sql语句

本文介绍了如何使用SQL语句进行数据库索引的创建、删除及修改操作,并演示了主键、唯一索引及普通索引的应用。此外,还详细说明了如何添加、删除表中的约束条件。

删除索引

drop index [User_Publish_ischeck] ON [dbo].[User_Publish]

 

删除主键

alter table User_Publish  drop constraint PK_User_Publish

 

创建索引
CREATE NONCLUSTERED INDEX [User_Publish_ischeck] ON [dbo].[User_Publish]
(
    [IsCheck] ASC
)

 

--创建非聚集索引

create nonclustered index inx_entry_stock_on entry_stock_d(entry_stock_bi)

 

--主键且非聚集
alter table entry_stock_d add primary key nonclustered--主键且非聚集
(
 entry_stock_bi,aid

}

 

创建唯一非聚集索引

CREATE UNIQUE INDEX AK_UnitMeasure_Name 
ON Production.UnitMeasure(Name);
GO

创建分区聚集索引

create clustered index PK_User_Publish_RefTime
on User_Publish(RefTime)
on RefTimePS(RefTime);

 

删除约束
alter table [User_Publish] drop constraint DF_User_Publish_IsCheck

 

增加约束
ALTER TABLE User_Publish
ADD CONSTRAINT DF_User_Publish_IsCheck DEFAULT (0)  FOR IsCheck

 

修改列的类型
ALTER TABLE User_Publish ALTER column IsCheck char(1) null

转载于:https://www.cnblogs.com/50614090/articles/1869114.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值