怎样在数据库中用sql语句约束字符类型的字段长度至少为六

怎样在数据库中用sql语句约束字符类型的字段长度至少为六,第1张

1、首先打开软件,进入界面。

2、接下来通过SQL语句进行修改,如下图所示,指定表明和字段即可。

3、上述的SQL语句会默认将允许NULL值给勾上,如下图所示。

4、如果不想让NULL值默认勾选上的话,就在SQL语句后面加上not  null条件即可。

5、最后在回到数据表的设计界面,就会看到字段长度已经增加,并且其他的数据条件没有变化。

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)我也是菜鸟一个 这么写看着确实有点傻


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

原文地址: https://outofmemory.cn/sjk/6912602.html

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

发表评论

登录后才能评论

评论列表(0条)

保存