Identity property

  • It’s possible to set up the Identity property when you create the table.

     

    CREATE TABLE [dbo].[T22] (

                [T22_Key] [int] IDENTITY (1, 1) NOT NULL ,

                [Profile_Key] [int] NULL )

    ON [PRIMARY]

     

     

    If the table was created without Identity using script:

     

    CREATE TABLE [dbo].[T22] (

                [T22_Key] [int]  NOT NULL ,

                [Profile_Key] [int] NULL )

    ON [PRIMARY]

     

    Is it possible to add Identity property on the existing column using alter table statement?

    This doesn’t work:

    alter table T22 alter column T22_Key int  IDENTITY (1, 1) NOT NULL 

     

    Are there any ways to set Identity programmatically through script?

  • AFAIK, no!

    You might want to try this in EM:

    Create a new table. Save it. Change a column to have the IDENTITY property defined on it. Click on Generate Change script. Now you see, what EM is doing behind the scenes. AFAIK, that is the only way to add that property to an existing column.

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

Viewing 2 posts - 1 through 1 (of 1 total)

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