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
 PrimaryKey

Author  Topic 

kidaduo
Starting Member

45 Posts

Posted - 2008-05-15 : 14:56:36
Hi,

Got a question. I have a script that create a table-- I need Col1, Col2 and Col3 to have PrimaryKey. How do u do. Here is the script

CREATE TABLE [dbo].[PROC_DATA] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[Col1] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Col2] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Col3] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Date1] [datetime] NOT NULL ,
[Recod1] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [DRI_CHASE_DATA_GRP1]
GO


Josephine

kidaduo
Starting Member

45 Posts

Posted - 2008-05-15 : 15:08:32
Sorry guys. Please, disregard this question.

Josephine
Go to Top of Page

kidaduo
Starting Member

45 Posts

Posted - 2008-05-15 : 15:22:14
I still need help! whatever, I had did not work. Please,help with the primary key

Josephine
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-05-15 : 15:42:33
Here's one way. You need to decide if want it clustered or nonclustered:

alter table Proc_data add constraint PK_Proc_data primary key nonclustered (col1, col2, col3)

Be One with the Optimizer
TG
Go to Top of Page

kidaduo
Starting Member

45 Posts

Posted - 2008-05-15 : 15:48:09
Thank u TG. That is what I was looking!



quote:
Originally posted by TG

Here's one way. You need to decide if want it clustered or nonclustered:

alter table Proc_data add constraint PK_Proc_data primary key nonclustered (col1, col2, col3)

Be One with the Optimizer
TG



Josephine
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-05-22 : 03:08:09
Hi,

Follow this script

CREATE TABLE [dbo].[PROC_DATA] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[Col1] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Col2] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Col3] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Date1] [datetime] NOT NULL ,
[Recod1] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_tbl_PROC_DATA] PRIMARY KEY CLUSTERED
(
[Col1] ASC,
[Col2] ASC,
[Col3] ASC
)
) ON [DRI_CHASE_DATA_GRP1]


Go to Top of Page
   

- Advertisement -