SQL语句添加约束--例子

create table Student 


sno varchar(10) not null unique, 
sname varchar(8) not null, 
sex char(2), 
age int not null, //加上非空限制 
dept varchar(20), 
constraint C_age default 20 for age, 
constraint C_sex check(sex in ('男','女')) 

go

 

create table Studp145ent( 
SID int identity,
SName varchar(16) not null,
SAddress varchar(32) ,
SSex char(2) not null constraint C_SSex54ip check(SSex in ('男','女')),
SAge int not null  default C_age 20,
SEmail varchar(16)
)

 

create table Student 

sno varchar(10) not null unique, 
sname varchar(8) not null, 
sex varchar(2) not null, 
age int, 
dept varchar(20), 

go 
Alter table Student Add constraint 
C_age default(20) for age 
go 
Alter table Student Add constraint 
C_sex check (sex in ('男','女')) 
go 

 

------------------------------------------------------

 

 

ALTER TABLE Q0T01

--add  ctest int 

ADD CONSTRAINT C_JJZQ CHECK(F_JJZQ in ('1','2','3','4'))

 

你可能感兴趣的:(SQL,SERVER基础知识,sql,null,table,c)