Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2011-10-05
2
Medium Priority
?
300 Views
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!
0
Comment
Question by:bbdesign
2 Comments
 
LVL 21

Accepted Solution

by:
JestersGrind earned 2000 total points
ID: 36918254
You can add an identity column to an existing table by running this.

ALTER TABLE YourTable ADD YourColumn INTEGER IDENTITY(1,1)

Greg

0
 

Author Comment

by:bbdesign
ID: 36919214
Works great, thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
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
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

581 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