How can i solve “An explicit value for the identity column in table”?

寵の児 提交于 2019-12-25 01:45:47

问题


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',
'',
'',
'',
'',
'',
'',
'' )

回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/3069420/how-can-i-solve-an-explicit-value-for-the-identity-column-in-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!