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
 General SQL Server Forums
 New to SQL Server Programming
 Set Primary Key To 2 Columns

Author  Topic 

rn5a
Starting Member

25 Posts

Posted - 2008-10-31 : 04:21:50
I have recently started using SQL Server 2005 Management Studio. I have a table with 5 columns. I want 2 of the columns to be the primary key columns. I tried setting the primary key columns in the SSMS IDE by clicking the 1st column, holding down the SHIFT key on the keyboard & then clicking the 2nd column but the focus shifts to the 2nd column. As a result I am not able set both the columns as the primary key columns.

How do I set both the columns as the primary key columns in the SSMS IDE?

Thanks,

Ron

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-31 : 04:36:12
Just use ALTER TABLE ADD CONSTRAINT... T-SQL statement for this
Go to Top of Page

rn5a
Starting Member

25 Posts

Posted - 2008-10-31 : 05:15:01
quote:
Originally posted by visakh16

Just use ALTER TABLE ADD CONSTRAINT... T-SQL statement for this

Please show me the syntax. I don't know it.

Thanks,

Ron
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-31 : 05:27:20
htp://doc.ddart.net/mssql/sql70/aa-az_5.htm
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-10-31 : 05:40:20
quote:
Originally posted by rn5a

quote:
Originally posted by visakh16

Just use ALTER TABLE ADD CONSTRAINT... T-SQL statement for this

Please show me the syntax. I don't know it.

Thanks,

Ron



ALTER TABLE tablename ADD CONSTRAINT pk_tablename_col1_col2 PRIMARY KEY CLUSTERED (col1,col2)

where col1,col2 are not null fields
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-10-31 : 05:48:06
quote:
Originally posted by visakh16

htp://doc.ddart.net/mssql/sql70/aa-az_5.htm



http://doc.ddart.net/mssql/sql70/aa-az_5.htm

't' is missing....
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-10-31 : 06:03:23
The "Shift way" of doing it also works fine, just make sure you click the gray area in front of the column name instead of inside the column name.

- Lumbago
Go to Top of Page
   

- Advertisement -