How can i solve “An explicit value for the identit

2019-08-23 09:36发布

if i try to add some data into my table error occurs:

Error:Msg 8101, Level 16, State 1, Line 1 An explicit value for the identity column in table 'ENG_PREP' can only be specified when a column list is used and IDENTITY_INSERT is ON.

insert into ENG_PREP VALUES('572012-01-1,572012-01-2,572012-01-3,572013-01-1,572013-01-2',
'',
'500',
'',
'A320 P.001-A',
'Removal of the LH Wing Safety Rope',
'',
'',
'',
'0',
'',
'AF',
'12-00-00-081-001',
'',
'',
'',
'',
'',
'',
'' )

2条回答
神经病院院长
2楼-- · 2019-08-23 10:09

Your statement

insert into ENG_PREP

will try to insert values into all of the columns of your table - including the IDENTITY column, where you should never insert a specific value.

What you need to do is specify which columns of your table you really want to insert values into, and leave out the IDENTITY column - that'll be automatically handled by SQL Server itself:

 INSERT INTO dbo.ENG_PREP(column1, column2, ...., columnX)
 VALUES(values1, values2, ...., valuesX)

You only need to specify those columns that you really want to set a value for (e.g. you can probably skip most of those columns where you just insert a '' in your example).

查看更多
在下西门庆
3楼-- · 2019-08-23 10:22

If you must write to the identity column, use

SET IDENTITY_INSERT YourTableName ON

just as the error message suggests.

Otherwise, don't try to write to the identity column.

查看更多
登录 后发表回答