插入查询、字符串或二进制数据将被截断
Insert query, string or binary data would be truncated
为什么这种情况一直发生?前 2 个数据类型是 Int
。 'Games' 是 DateTime
。最后一个是VarChar
。为什么执行不成功
varchar
用作列数据类型时的默认长度为 1。
varchar [ ( n | max ) ] Variable-size string data
. . .
When n isn't specified in a data definition or variable declaration
statement, the default length is 1. If n isn't specified when using
the CAST and CONVERT functions, the default length is 30.
char and varchar (Transact-SQL)
因此您需要为列设置最大长度。乙
use tempdb
go
drop table if exists JaretsSchedule
go
create table JaretsSchedule
(
FieldId int,
TeamID int,
Games datetime,
TeamsPlaying varchar(255)
)
go
insert into JaretsSchedule(FieldId,TeamID,Games,TeamsPlaying)
values (1,1,'2012-01-20 10:00:00','Roadrunnersv.s.Cheetahs')
因为,您已经超出了字段的最大大小,
ALTER TABLE JaretsSchedule ALTER COLUMN TeamsPlaying nvarchar(1000);
为什么这种情况一直发生?前 2 个数据类型是 Int
。 'Games' 是 DateTime
。最后一个是VarChar
。为什么执行不成功
varchar
用作列数据类型时的默认长度为 1。
varchar [ ( n | max ) ] Variable-size string data
. . .
When n isn't specified in a data definition or variable declaration statement, the default length is 1. If n isn't specified when using the CAST and CONVERT functions, the default length is 30.
char and varchar (Transact-SQL)
因此您需要为列设置最大长度。乙
use tempdb
go
drop table if exists JaretsSchedule
go
create table JaretsSchedule
(
FieldId int,
TeamID int,
Games datetime,
TeamsPlaying varchar(255)
)
go
insert into JaretsSchedule(FieldId,TeamID,Games,TeamsPlaying)
values (1,1,'2012-01-20 10:00:00','Roadrunnersv.s.Cheetahs')
因为,您已经超出了字段的最大大小,
ALTER TABLE JaretsSchedule ALTER COLUMN TeamsPlaying nvarchar(1000);