用 T—sql 代码
alter table patinfo
add constraint ck_patid check(patid like'p26[0-9][0-9]'),
add constraint Ck_patSex check(sex = '女' or sex = '男'),
add constraint ck_patage check(age>=1 and age<=99),
add patbno identity(1,1) constraitnt ck_patbno check(patbno(21),
add constraint df_pataddress default'地址不详'for pataddress
----------------------------------------
无法执行,要求: patid 要是p26**格式
patsex 只能是男女
patage 必须在1~99之间
patbno 自动编号,且在1~20之间
pataddress 可不填,但没有填写时,显示“地址不详”
------解决方案--------------------------------------------------------
楼主有几个地方拼错了,还有就是要保证dbo.Patinfo表里的数据都符合条件,改之前先select 一下
- SQL code
Alter Table dbo.Patinfo Add Constraint CK_Patid Check(Patid Like'p26[0-9][0-9]')Alter Table dbo.Patinfo Add constraint CK_PatSex Check(Sex = N'女' Or Sex = N'男')Alter Table dbo.Patinfo Add constraint CK_Patage Check (Age>=1 And Age<=99)Alter Table dbo.Patinfo Add Patbno int Identity(1,1) constraint CK_Patbno Check(Patbno<21)Alter Table dbo.Patinfo Add constraint DF_Pataddress Default N'地址不详' for Pataddress