how to set and reset column identity by a query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    how to set and reset column identity by a query?

    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
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by nirmalsingh
    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

    Comment

    Working...