tags:

views:

124

answers:

2

I have many tables; each has a primary key which is an Identity column with a seed of 1.
I have another program which converts data from a previous database (dBase) to sql.
This programs needs Indentity = No.
How can I change Identity and Identity Seed from my code?

+2  A: 

There's no need to break the table for the sake of a data import, just do this:

set identity_insert MyTable on

insert into MyTable ... blah blah blah

set identity_insert MyTable off
Christian Hayter
i wish i could set two answers as good answer.
Behrooz
+3  A: 

It sounds like you want to insert values into the IDENTITY column

You can do that using

SET IDENTITY_INSERT TableName ON

INSERT INTO MyTable (IdentityColumn, Column1, Column2) Values (1, 2, 3)

SET IDENTITY_INSERT TableName OFF

Note: you must specify all the column names

To reseed identity (to lets say start at 77) use the following command

dbcc checkident(TableName, RESEED, 77)
Raj More