--- I have done this before, but I have encountered it in the project, but I cannot remember it at half past one ~~~
Find http://hi.baidu.com/grrc/blog/item/16d216a85b61bbb6ca130c13.html.Article.
Now, I will extract the content of this article for your note:
Generally, values cannot be inserted into the SQL Server auto-increment field. If this is the case, SQL Server will give you an error warning:
Server: MSG 544, level 16, state 1, line 1 cannot insert explicit value for identity column in table 't'when identity_insert is set to off.
This error message prompts that if you insert a value to the SQL Server field, you need to set the identity_insert option to on.
Set identity_insert on
Let's look at a specific example:
Create Table DBO. t (ID int identity (1, 1) not null, name varchar (50 ))
Set identity_insert t oninsert into T (ID, name) values (1, 'sqlstudy ') set identity_insert t off
Note that after the auto-increment field is inserted, you must set identity_insert to off in time.