首页 > 解决方案 > INSERT 语句与 CHECK 约束冲突(插入表问题)

问题描述

我正在处理数据库并为电话号码设置了检查约束。但是我在输入电话号码时遇到问题。

我尝试插入不带“”的电话号码,但仍然无效

create table CustomerDetails.Clients (
Client_ID int primary key identity (100, 10),
Company_Name varchar (35) not null, 
Contact_Person char (35) not null,
City char (20) not null, 
State char (20) not null,
Zip int not null,
Country char (45) not null,
Phone varchar (30) not null
CONSTRAINT chk_Phone CHECK 
(Phone 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]')
);

insert into CustomerDetails.Clients values ('Bazz Beauty Home', 'Felix Jhean', 
    'Ohio', 'Cincinnati', '350056', 'United States', '34-453-5458-698-978')

标签: sql-serverstringbinarytruncated

解决方案


34-453-5458-698-978 is 19 characters long, but your phone number column is varchar(18). You should increase the length of your Phone column.


推荐阅读