[英]check constraint
hi i want add constraint in sql server i try this but not work i needd check if a word 2 char and 3 numbers after example aa192: 嗨,我想在SQL Server中添加约束,我尝试这样做,但不起作用,我需要检查示例aa192之后是否单词2 char和3数字:
create table test(
idtest int primary key ,
neEdition varchar(50)
);
alter table test add constraint ch_like check(neEdition like'[a-z][a-z][0-9][0-9][0-9]');
You code works in rextester . 您的代码可以在rextester中工作 。
Given what you are doing, I would recommend that the edition be declared to have 5 characters: 鉴于您正在做什么,我建议将版本声明为5个字符:
neEdition varchar(5)
or: 要么:
neEdition char(5)
That is more consistent with the check constraint. 这与检查约束更加一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.