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.
| Author |
Topic |
|
d3ng
Yak Posting Veteran
83 Posts |
Posted - 2008-01-17 : 02:33:05
|
| Hi experts, I would like to ask how to set 2 primary keys in one table? |
|
|
ssnaik84
Starting Member
15 Posts |
Posted - 2008-01-17 : 02:37:28
|
| No. You can't set 2 PKs in one table.If you wish, you can set PK for combination of 2/more columns (composite PK) |
 |
|
|
d3ng
Yak Posting Veteran
83 Posts |
Posted - 2008-01-17 : 02:40:32
|
| How to set composite PK? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-17 : 02:56:37
|
How do you normally create your table ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
d3ng
Yak Posting Veteran
83 Posts |
Posted - 2008-01-17 : 03:03:12
|
| I tried to highlight 2 columns in a design view of my table then click primary those two selected columns set as primary keythis is the scripts:USE [for_tester_only]GO/****** Object: Table [dbo].[darren_table] Script Date: 01/17/2008 15:58:40 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[darren_table]( [pkeyno1] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [pkeyno2] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [fullname] [nchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, CONSTRAINT [PK_darren_table] PRIMARY KEY CLUSTERED ( [pkeyno1] ASC, [pkeyno2] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-17 : 03:18:42
|
script looks ok. Do you got any error with this ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2008-01-17 : 07:47:53
|
| the script is correct. The only thing i would change is take out the collate details, unless you have a specific need for themJack Vamvas--------------------Search IT jobs from multiple sources- http://www.ITjobfeed.com |
 |
|
|
|
|
|
|
|