Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 16549 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > how to create primary keys on mulitple columns ...
Parthibansk

how to create primary keys on mulitple columns

Replies: 9 | Posted by: Parthibansk on 8/7/2012 | Category: Sql Server Forums | Views: 482 | Status: [Member] | Points: 10  


how to create primary keys on mulitple columns..


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Oswaldlily
Oswaldlily  
Posted on: 8/7/2012 1:57:00 AM
Level: Starter | Status: [Member] | Points: 25

Take Table page where yu ll allocate datatypes to each column name.
There right click on column name where u want to set primary key and
select "Set as Primary Key"

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

San.Pblr.Gct
San.Pblr.Gct  
Posted on: 8/7/2012 2:30:32 AM
Level: Starter | Status: [Member] | Points: 25

Create table tbl_CustomerProducts
(
CustomerID int not null,
ProductID int not null,
OrderLimit int not null,
Primary key (CustomerID, ProductID)
)


In the above table creation, i have used composite primary key i.e. combination of multiple columns for primary key

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 8/7/2012 2:31:35 AM
Level: Silver | Status: [Member] | Points: 25

In SQL server management studio,
1. select the table design
2.Click control key(Ctrl) and select(click) the columns that you need to set primary key,and then click 'Set as primary key'
3.This creates primary key on multiple columns.

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sandeepkasar
Sandeepkasar  
Posted on: 8/7/2012 2:57:19 AM
Level: Starter | Status: [Member] | Points: 25

CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
)

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Pandians
Pandians  
Posted on: 8/7/2012 5:12:56 AM
Level: Silver | Status: [Member] [MVP] | Points: 25

Check it out!

1. Add composite Primary key when creating a Table:
Create Table MultiplePK

(
Id Int Identity(1,1) Not Null,
Column1 Varchar(10) Not Null,
Column2 Varchar(10), Constraint PK_Id_Column1_MultiplePK Primary Key(Id, Column1)
)
Go
2. Add composite Primary key on existing Table:
Alter Table MultiplePK Add Constraint PK_Id_Column1_MultiplePK Primary Key(Id, Column1)

Go
Kindly make as Answer any one of the reply! Pls

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Sriramnandha
Sriramnandha  
Posted on: 8/9/2012 8:51:38 AM
Level: Starter | Status: [Member] | Points: 25

create table test(id int,userid int,pincode int,name varchar(90) ,primary key (int,userid,pincode))



sriram

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Muhsinathk
Muhsinathk  
Posted on: 9/4/2012 3:34:21 AM
Level: Bronze | Status: [Member] | Points: 25

CREATE TABLE table1(
ClassID int,
StudentID int,
location varchar(2),
Constraint PK_table1 PRIMARY KEY(ClassID, StudentID))

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Pandians
Pandians  
Posted on: 9/4/2012 4:42:37 AM
Level: Silver | Status: [Member] [MVP] | Points: 25

Hey Parthibansk

You didn't get clarified yet ? Kindly Make any one of the reply as "ANSWER" Pls :)

Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Maheshvishnu
Maheshvishnu  
Posted on: 9/4/2012 5:07:18 AM
Level: Starter | Status: [Member] | Points: 25

Go through Table Level constraints Concepts

mahesh

Parthibansk, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 2:09:16 PM