我有一个表,其中contact是一列,约束模式为(000)0000000000
create table patient
(USERNUM INT PRIMARY KEY,
CONTACT varchar(15) constraint check_contact check (contact like '%([0-9]*3)[0-9]*10%'),
age int constraint check_age check (age >0 and age <=100),
location varchar(50)
);
虽然数字的模式相同,但这不允许我插入记录。
我已经用下面的命令更改了我的表格
alter table patient add contact varchar(15) constraint ch_contact
check (SUBSTRING(contact, 1, 1) = '(' and SUBSTRING(contact, 5, 1) = ')'
and SUBSTRING(contact, 2, 4) like '[0-9]' and SUBSTRING(contact, 6, 15) like '[0-9]');
但它不允许我插入以下记录
insert into patient (USERNUM, CONTACT, AGE, LOCATION)
VALUES (5, '(000)0234567890', 34, 'VIZAG');
'''