How to solve the SQLServer IDENTITY_INSERT problem
This article mainly introduces "how to solve the SQLServer IDENTITY_INSERT problem". In the daily operation, I believe that many people have doubts about how to solve the SQLServer IDENTITY_INSERT problem. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to solve the SQLServer IDENTITY_INSERT problem"! Next, please follow the editor to study!
Question:
Columns with self-increasing attributes cannot perform insert into operations directly
Create table chenjch_tbs01 (id int IDENTITY (1) NOT NULL,age int)
Insert into chenjch_tbs01 values (1 dint 1)
Message 8101, level 16, status 1, line 1
Explicit values can be specified for identity columns in table 'chenjch_tbs01' only if column lists are used and IDENTITY_INSERT is ON.
Insert into chenjch_tbs01 (id,age) values (1BI 1)
Message 544, level 16, status 1, line 1
When IDENTITY_INSERT is set to OFF, explicit values cannot be inserted for the identity column in the table 'chenjch_tbs01'.
Resolve:
SET IDENTITY_INSERT chenjch_tbs01 ON
-select * from sys.objects where type='U' and name='chenjch_tbs01';-object_id=980406762
-- select column_id,name from sys.columns where object_id=980406762 order by column_id
Insert into chenjch_tbs01 (id,age) values (1BI 1)
At this point, the study on "how to solve the SQLServer IDENTITY_INSERT problem" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!