我创建了一个表并将值添加到该表中。在“ HomePhone”字段中添加值时,我将数据值设置为“ null”。之后,我执行了查询,显示了错误。后来,我决定通过编码为''将数据保留为空白。
错误消息显示为
“字符串或二进制数据将被截断。该语句已被 终止。”
/* Creating table6 Customer */
create table Customer
(
CustomerID int primary key identity(301,1) not null,
AccountID int not null,
CustomerAddress1 varchar(30),
CustomerAddress2 varchar(30),
CustomerFirstName varchar(30),
CustomerMiddleInitial char(1),
CustomerLastName varchar(30),
City varchar(20),
St_ate char(2),
ZipCode char(10),
EmailAddress varchar(40),
HomePhone char(10),
CellPhone char(10),
WorkPhone char(10),
SSN char(9),
UserLoginID smallint not null
);
/ *将5行值添加到table6客户* /
insert into Customer(AccountID,CustomerAddress1,CustomerAddress2,CustomerFirstName,CustomerMiddleInitial,CustomerLastName,City,
St_ate,ZipCode,EmailAddress,HomePhone,CellPhone,WorkPhone,SSN,UserLoginID)
values
(102,'456 DEF Street','Unit 12','Williams','Kevin','George','London','ON','M5D1B3','kevin@xyz.com',' ','3366991100','1234567890','456789012',2),
(103,'789 PQR Street','Unit 20','Lindsay','Steffi','Davidson','Seattle','WA','98128','lindsay@xyz.com','6547893210','3366991100',' ','876543219',3);
我希望查询能够正确执行。
答案 0 :(得分:1)
错误消息清楚地说明,您要插入的值之一大于表中定义的列的长度。
在您的情况下,您已将CustomerMiddleInitial
定义为char(1
),因此不应在此列值中输入多个字符,而是尝试插入以下值。
Kevin
Steffi
要么更改表以增加列长度,要么仅对列CustomerMiddleInitial
指定一个字符