sql中,要求只能是8位字符,前两位是0,3~4位为数字,第五位为下划线,6~8位为字母,怎么写check约束条件!
1个回答
展开全部
可以这样写
alter table table1 add constraint chk_col check(
len(col1)= 8 and
left(col1,2) = '00' and
substring(col1,3,1) like '[1-9]' and
substring(col1,4,1) like '[1-9]' and
substring(col1,5,1) = '_' and
substring(col1,6,1) like '[A-Z]' and
substring(col1,7,1) like '[A-Z]' and
substring(col1,8,1) like '[A-Z]' );
alter table table1 add constraint chk_col check(
len(col1)= 8 and
left(col1,2) = '00' and
substring(col1,3,1) like '[1-9]' and
substring(col1,4,1) like '[1-9]' and
substring(col1,5,1) = '_' and
substring(col1,6,1) like '[A-Z]' and
substring(col1,7,1) like '[A-Z]' and
substring(col1,8,1) like '[A-Z]' );
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询