首先澄清一下,我已经已经完成了搜索,发现了一些相同的问题,但答案并没有解决我的问题。
我有这段代码:
SET IDENTITY_INSERT [STUDY] ON
INSERT INTO [STUDY]
([STUDY_ID],[PARENT_ID],[GROUP_ID],[WORKFLOW_NODE_ID],[STUDY_TEMPLATE_ID]
,[INSPECTION_PLAN_ID],[NAME],[DESCRIPTION],[STATUS],[OLD_STATUS],[CREATED_ON],[COMPLETED_ON]
,[AUTHORIZED_ON],[EVENTS],[NEEDS_REVIEW],[HAS_NOTES],[HAS_AUDITS],[STUDY_PART],[STUDY_TYPE]
,[EXTERNAL_REFERENCE],[CREATED_BY],[COMPLETED_BY],[AUTHORISED_BY],[ARCHIVED_CHILD_COMPLETE])
VALUES (12345,null,null,1234,12,null,'asdf / asdf','blahblahblah','A','VPC','2010-07-01','2010-08-05','2010-09-04','(asdf,1234,#1234,F,T)','F',null,null,'F',null,'1234',1234,1234,1234,'F')
SET IDENTITY_INSERT [STUDY] OFF
当我运行它时,我收到此错误:
Msg 8152, Level 16, State 14, Line 2
String or binary data would be truncated.
The statement has been terminated.
以下是STUDY
的创建脚本:
CREATE TABLE [dbo].[STUDY]
(
[STUDY_ID] INT IDENTITY(1,1) NOT NULL,
[PARENT_ID] BIGINT,
[GROUP_ID] BIGINT,
[WORKFLOW_NODE_ID] BIGINT,
[STUDY_TEMPLATE_ID] BIGINT,
[INSPECTION_PLAN_ID] BIGINT,
[NAME] VARCHAR(255),
[DESCRIPTION] VARCHAR(4000),
[STATUS] VARCHAR(5),
[OLD_STATUS] VARCHAR(5),
[CREATED_ON] DATE,
[COMPLETED_ON] DATE,
[AUTHORIZED_ON] DATE,
[EVENTS] VARCHAR(255),
[NEEDS_REVIEW] VARCHAR(1),
[HAS_NOTES] VARCHAR(1),
[HAS_AUDITS] VARCHAR(1),
[STUDY_PART] VARCHAR(1),
[STUDY_TYPE] VARCHAR(255),
[EXTERNAL_REFERENCE] VARCHAR,
[CREATED_BY] BIGINT,
[COMPLETED_BY] BIGINT,
[AUTHORISED_BY] BIGINT,
[ARCHIVED_CHILD_COMPLETE] VARCHAR(1)
PRIMARY KEY CLUSTERED
(
[STUDY_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
答案 0 :(得分:7)
EXTERNAL_REFERENCE
被声明为VARCHAR
,被视为VARCHAR(1)
。
您正试图将'1234'
插入此字段。
答案 1 :(得分:1)
假设我正确计算字段,您已定义“[EXTERNAL_REFERENCE] VARCHAR”,其默认长度为1个字符,但您提供的数据为“1234” - 4个字符