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 2005 Forums
 Transact-SQL (2005)
 Two primary keys

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-05-13 : 09:24:04
How to add two primary keys in two columns?
In my table, only allow me to add one primary key in on column.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-13 : 09:37:06
you can have only one primary in a table but you can define more than one column as the primary key


create table tab1 (
col1 varchar(10) not null,
col2 integer not null,
col3 decimal(20,2) null,
constraint PK_tab1 primary key (col1, col2)
)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kishore_pen
Starting Member

49 Posts

Posted - 2009-05-13 : 09:39:58
use Partitions in your database. for more info see SQL BOL.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-13 : 10:01:01
quote:
Originally posted by Sun Foster

How to add two primary keys in two columns?
In my table, only allow me to add one primary key in on column.


can i ask why you want multiple primary keys?
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-05-13 : 11:18:29
I just want to copy a table in another app which we bought.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-13 : 11:23:13
so? whats the need of two primary keys there? you need a single pk there. if your effort is to ensure pk field of first table still has only unique values, why dont create a unique constraint on it?
Go to Top of Page
   

- Advertisement -