SQL编写身份证约束

来源:百度知道 编辑:UC知道 时间:2024/09/24 00:26:44
怎么用SQL编写身份证约束
用代码 PID int not null default 后面的约束

alter table 表名 add
constraint CK_PID check(len(PID) = 15 or len(PID)=18)
--身份证的长度是15或者18位

15位老身份证18为是新的.

add constraint ck_列名 check(列名 like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or 列名 like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' or len(列名)=18)