469,330 Members | 1,365 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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 2206
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.