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)
 Alter table column to primary key column

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2012-06-12 : 17:47:25
How can i make the following column as primary key column via alter table alter column statement?

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



ALTER TABLE Tab_workflows ALTER COLUMN activityid [int] IDENTITY(1,1) NOT NULL


Thanks a lot for the helpful info.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-06-12 : 18:19:41
ALTER TABLE Tab_workflows ADD CONSTRAINT PK_Tab_workflows PRIMARY KEY(ActivityID)
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2012-06-13 : 06:58:54
Thanks worked perfectly fine.

Go to Top of Page

prett
Posting Yak Master

212 Posts

Posted - 2012-06-13 : 07:18:15
To create a PRIMARY KEY constraint on the "[ActivityID] column when the table is already created, use the following query:
ALTER TABLE 'table name' ADD PRIMARY KEY (column name);
Go to Top of Page

granuharmot
Starting Member

31 Posts

Posted - 2014-09-23 : 05:18:17
unspammed
Go to Top of Page
   

- Advertisement -