SQL里怎么使用Like语句来进行约束

SQL里怎么使用Like语句来进行约束,第1张

楼上正解,如果要规定手机号码首位为1,可以定义CHECK约束为:

(手机号 LIKE '1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')

alter table CS01 add constraint CK_A800 check (LEN(A8)=8)

alter table CS01 add constraint CK_A8001 check (A8 like '00%')

alter table CS01 add constraint CK_A8003 check (ascii(substring(A8,3,1))>=48 and ascii(substring(A8,3,1))<=57)

alter table CS01 add constraint CK_A8004 check (ascii(substring(A8,4,1))>=48 and ascii(substring(A8,4,1))<=57)

--下划线是通配符

alter table CS01 add constraint CK_A8005 check (ascii(substring(A8,5,1))>=ascii('_'))

--只允许输入大写字母

alter table CS01 add constraint CK_A8006 check (ascii(substring(A8,6,1))>=65 and ascii(substring(A8,6,1))<=90)

alter table CS01 add constraint CK_A8007 check (ascii(substring(A8,7,1))>=65 and ascii(substring(A8,7,1))<=90)

alter table CS01 add constraint CK_A8008 check (ascii(substring(A8,8,1))>=65 and ascii(substring(A8,8,1))<=90)我也是菜鸟一个 这么写看着确实有点傻


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6830514.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-28
下一篇 2023-03-28

发表评论

登录后才能评论

评论列表(0条)

保存