首先澄清一下,我已经做了搜索,发现了几个相同的问题,但答案并没有解决我的问题。
我有这个代码:
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]
最佳答案
EXTERNAL_REFERENCE
被声明为 VARCHAR
,它被视为 VARCHAR(1)
。
您正在尝试将 '1234'
插入此字段。
关于sql - 字符串或二进制数据将被截断,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4145348/