472,107 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,107 software developers and data experts.

how to set and reset column identity by a query?

nirmalsingh
218 100+
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
1 2287
ck9663
2,878 Expert 2GB
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.

Similar topics

2 posts views Thread by Ryan P. Kennedy | last post: by
6 posts views Thread by Who.Really.Really.Cares | last post: by
reply views Thread by Frank Swarbrick | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.