Removing Identy using T-SQL

  • There is a table with an identity column created and it might or might not have data. I need to remove this identity from that column. how do i do it with T-SQL?

    Can anyone help??

    Thanks

  • You cannot remove the identity property from a column.  You can disable the property using SET IDENTITY INSERT.



    --Jonathan

  • Thanks Jonathan,

    But i removed the identity using ALTER TABLE ALTER COLUMS statement, by redifining the column without the identity

    Cheers

    Vikram:-)

  • Are you sure?  What is the eaxct statement you used?  I see no support for this in the ALTER TABLE ALTER COLUMN syntax, and this certainly doesn't remove the property:

    use tempdb

    go

    create table test(id int identity)

    alter table test alter column id int

    sp_help test



    --Jonathan

  • Hi Jonathan

    you were right. I cannot remove the identity. I need to drop and recreate the table without the identity.

    Thanks

  • Actually, why dropping the table?

    What about adding an int column, update that new column with the values of your 'identity' column, drop that identity column, and rename the int column?

    Well, okay, dropping might seem easier

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply