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
 primary key

Author  Topic 

sandeep1209
Starting Member

6 Posts

Posted - 2012-03-23 : 14:52:25
Hi guys,

I want to crate primary key for 2 columns in the table, as well as i need to create more that 2 columns. I'm trying to create primary key like following way

create table usern(userid varchar(20),fname varchar(20),lname varchar(20),village varchar(20) references Towns(tname),phone int,relationship varchar(20)),constraint pl_vilage primary key (fname,lname)

-- here i want to create 2 primary key columns those are fname and lname

Any one assist me how i need to over come form this problem.

Thank's

Sandeep.

sandeep

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-23 : 14:59:02
and....

what's the problem?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-03-23 : 16:06:18
I'm not sure I understand either, but are you asking how to create the primary key constraint outside the table creation? If so, try this:
ALTER TABLE dbo.usern
ADD CONSTRAINT pl_vilage PRIMARY KEY CLUSTERED (fname,lname)
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-03-23 : 17:22:01
quote:
Originally posted by X002548

and....

what's the problem?


Other than wanting a primary key on a person's name?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-23 : 21:12:10
quote:
Originally posted by GilaMonster

quote:
Originally posted by X002548

and....

what's the problem?


Other than wanting a primary key on a person's name?

--
Gail Shaw
SQL Server MVP



Details, Details...if we had to stop and question everyone's motives..oh wait a minute...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -