SQL Server Identity field
-
I have a table with a field defined as the primary key and as auto incremented. Does anyone have an idea on how to insert data into the table overriding the auto increment property, so that I can insert my vaalues for this field as well. I want to know if there is a way to do this using ADO and the Open and AddNew methods.:confused: Kostas Stefanou
-
I have a table with a field defined as the primary key and as auto incremented. Does anyone have an idea on how to insert data into the table overriding the auto increment property, so that I can insert my vaalues for this field as well. I want to know if there is a way to do this using ADO and the Open and AddNew methods.:confused: Kostas Stefanou
You can use something like SET IDENTITY_INSERT T1 ON INSERT INTO T1 (column_1,column_2) VALUES (-99,'Explicit identity value') - Anders
-
You can use something like SET IDENTITY_INSERT T1 ON INSERT INTO T1 (column_1,column_2) VALUES (-99,'Explicit identity value') - Anders
At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for. If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value. The setting of SET IDENTITY_INSERT is set at execute or run time and not at parse time. :|