• I have to respectfully disagree with the posters that are saying that using the GUI is the best approach. If by best you mean easiest, then that would be true. But if you look at what is involved, the article really dives into an interesting and super-efficient way to accomplish the task. If you had a 120gb table (as I have had), and you do this through the GUI (or script what the GUI would do and run it), you would find your users very displeased at the amount of downtime, assuming you dont run out of diskspace while your query creates a copy of the table with a new identity column. This is what the GUI does, if you wanted to add an identity to a table without one (in 2005)...

    BEGIN TRANSACTION

    GO

    CREATE TABLE dbo.Tmp_SourceTable

    (

    Id int NOT NULL IDENTITY (1, 1),

    Column1 varchar(50) NULL,

    Column2 varchar(50) NULL

    ) ON [PRIMARY]

    GO

    SET IDENTITY_INSERT dbo.Tmp_SourceTable OFF

    GO

    IF EXISTS(SELECT * FROM dbo.SourceTable)

    EXEC('INSERT INTO dbo.Tmp_SourceTable (Column1, Column2)

    SELECT Column1, Column2 FROM dbo.SourceTable WITH (HOLDLOCK TABLOCKX)')

    GO

    DROP TABLE dbo.SourceTable

    GO

    EXECUTE sp_rename N'dbo.Tmp_SourceTable', N'SourceTable', 'OBJECT'

    GO

    COMMIT

    If i didnt have another 120gb on my disk, i would not be able to do the above based on diskspace alone.

    Very nice and very interesting article.