how to add an identity column to an existing table using script

Posted on 2011-10-05
Last Modified: 2012-05-12
I have an existing ASP script which generates a new table, by doing a CREATE TABLE statement, a bunch of columns, then at the end:

lm_index INT IDENTITY (1, 1) NOT NULL

...which creates an integer column called lm_index, as an identity column, auto-increment beginning with 1. Works great.

However, now I have a need to add this same exact type of column to an existing table. Can that be done just as easily?

Sorry if this is a very basic question, but I need to do this the right way the first time, and building/altering tables via a script is not something I do very often.

Thank you!
Question by:bbdesign
    LVL 21

    Accepted Solution

    You can add an identity column to an existing table by running this.




    Author Comment

    Works great, thanks!

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    This is my first ever Article on EE or elsewhere; therefore, please bear with me if I have some discrepancies in my writing. I read many articles and questions related to "how to pass values to SSIS packages at run-time?"  Hence, this common ques…
    I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now