码迷,mamicode.com
首页 > 数据库 > 详细

sql server 我常用的语句

时间:2018-09-02 20:30:25      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:enc   com   serve   clu   cas   const   null   create   compute   

1. computed column 

alter table tableName add columnName as (cast(aColumn as float) / bColumn * 100) persisted; 

 

2. unique nullable 

create unique nonclustered index[UniqueName] on [tableName]([columnNameA] asc) where ([columnNameA] is not null);

 

3. foreign key cascade delete 

alter table [tableNameA] drop constraint [FKName];
alter table [tableNameA] with check add constraint [FKName] foreign key(foreignColumnName) references [tableNameB]([Id]) on delete cascade -- or on delete set null;

 

4. reset auto increment 

dbcc checkident (tableName) --check current
dbcc checkident (tableName, reseed, 0); --reset to 0 , next is 1

 

sql server 我常用的语句

标签:enc   com   serve   clu   cas   const   null   create   compute   

原文地址:https://www.cnblogs.com/keatkeat/p/9574720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!