Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to add extra column in table by query?

Author  Topic 

asp__developer
Posting Yak Master

108 Posts

Posted - 2011-10-03 : 08:00:32
I have a table in which there is no primary key and there is data already in that table.

How to add extra column in table by query when there is already data in that table?

In the query while adding that new column/field, how to make it PRIMARY KEY and make it Increment value so that number increases for each row?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-03 : 08:06:50
ALTER TABLE <tablename> ADD <columnname> int IDENTITY(1,1) NOT NULL PRIMARY KEY

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

asp__developer
Posting Yak Master

108 Posts

Posted - 2011-10-03 : 11:27:56
Thank You
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-03 : 11:58:57
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -