34,590
社区成员
发帖
与我相关
我的任务
分享
create table t(sex nchar(4) default('男') check(sex not in (N'男', N'女')))
insert t select '男'
--error
insert t select '男'
--error
insert t select '不男不女'
--success
select * from t
drop table t
create table t(sex nchar(1) default('男') check(sex in (N'男', N'女')))
insert t select '男'
select * from t
drop table t
create table #t(sex nchar(2),col2 int)
alter table #t
add constraint check_cons check(sex in(N'男',N'女'))
go
alter table #t
add constraint df_cons default N'男' for sex
go
insert into #t(sex,col2) values(N'男',12)
insert into #t(sex) values(N'神')
insert into #t(col2) values(12)
select * from #t
drop table #t