SQLServer默认值约束

1. 创建表时指定默认值

[sql]  view plain  copy
  1. create table dbo.t1 (  
  2.     id1 INT  DEFAULT 5  
  3. )  

2. 创建表时指定默认值,并指定约束名

[sql]  view plain  copy
  1. create table dbo.t1 (  
  2.     id1 INT  CONSTRAINT df_t1_id1 DEFAULT 5  
  3. )  

3. 创建表时没有指定默认值,通过sql命令添加默认值

[sql]  view plain  copy
  1. create table dbo.t1 (  
  2.     id1"white-space:pre"INT  
  3. )  
[sql]  view plain  copy
  1. alter table dbo.t1 add default 5 for id1  

4. 通过sql命令添加默认值,并指定约束名称

[sql]  view plain  copy
  1. create table dbo.t1 (  
  2.     id1 INT  
  3. )  
[sql]  view plain  copy
  1. alter table dbo.t1 add constraint df_t1_id1 default 5 for id1  

5. 删除默认值约束

[plain]  view plain  copy
  1. alter table dbo.t1 drop constraint 约束名  

你可能感兴趣的:(SqlServer)