By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,623 Members | 1,892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,623 IT Pros & Developers. It's quick & easy.

how to set and reset column identity by a query?

nirmalsingh
100+
P: 218
hai all,

table : country
primary key: country_id (identity not set)

my question is.

i want to change country_id property to set identity, and insert a record and then i want to release identity (identity set=off).
how to write a query for it?
thanx in advance.
Regards Nirmal
Feb 29 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
hai all,

table : country
primary key: country_id (identity not set)

my question is.

i want to change country_id property to set identity, and insert a record and then i want to release identity (identity set=off).
how to write a query for it?
thanx in advance.
Regards Nirmal

Option 1:
1. Alter your table to set identity property to country_id.
2. Insert the record.
3. Alter the table back to remove identity.

Option 2:
1. Use IDENTITY() function in SELECT INTO to create a new table.
2. Inspect the new table.
3. Truncate your current table
4. Insert the new table to your current one
5. Drop your new table

Option 3:
If you only need something sequential:
Try this

Happy coding

-- CK
Feb 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.