Can a primary key contain more than one columns ?

Showing Answers 1 - 75 of 76 Answers

mahendra

  • Aug 23rd, 2005
 

Composite primary keys are based on more than one column

Allam Ravi

  • Aug 26th, 2005
 

NO, A table can have Only One primary key. 
but a table can have any number of composite primary key's

maheshwari

  • Nov 7th, 2005
 

no

  Was this answer useful?  Yes

PrasadVB

  • Nov 8th, 2005
 

Yes. A primary key can have more than one column. If it does .. it is called a Composite Primary Key. But a table cannot have more than one promary key. Hope this answers your question.

  Was this answer useful?  Yes

nitin

  • Aug 25th, 2006
 

hi everyone!
yes PK can have more than one column! it is used as compostie PK!
we can have this composite PK with an table!

Rohan Deshpande

  • Jan 13th, 2007
 

No. primary can't be imposed on more than column separately.if it shard then it is called as composite primary key.

  Was this answer useful?  Yes

shikha

  • Apr 9th, 2007
 

Yes. A primary key can have more than one column. If it has have more than one column it is called a Composite Primary Key.

Tarun

  • May 3rd, 2007
 

Yes, a primary key can contain more than one column. such a primary key is called a composite primary key.

  Was this answer useful?  Yes

amit verma

  • May 22nd, 2007
 

Yes. for a table only one primary key allow but,A primary key can have more than one column. If it has have more than one column it is called a Composite Primary Key. create table emp (emp_id number(12) ,name varchar2(12) ,primary key(emp_id,name);

  Was this answer useful?  Yes

velsowmya

  • Aug 7th, 2007
 

A tabel can have one primary key.but a primary key can hold more then one colum in a table.this key is known as composite key

  Was this answer useful?  Yes

Sujatars

  • Aug 8th, 2007
 

There can be only one primary key on a table but a primary key can be on?many columns which is called composite primary key

  Was this answer useful?  Yes

hi Buddy,
   Yes, IN sql we have define primary key in two way 
  1-Column lavel
  2-Table lavel (Composite  key)

IN column lavel we have define only one primary key in a table.
Create table a(id number(10) constraints v_pk primary key,ename varchar(20));

In table level u can create maximum 32 column PK .
create table a(id number(10) ,fname varchar2(20),lname varchar2(10),mobno number(10),constraints v_pk primary key(id,mobno));

  Was this answer useful?  Yes

sumanpani

  • Sep 16th, 2008
 

Yes, we can create primary key more than one column by using Table Level Like

ALTER TABLE table add CONSTRAINTS pk_22 PRIMARY KEY(COLUMN1,COLUMN2);

  Was this answer useful?  Yes

narmadac

  • Feb 11th, 2010
 

A table can have only one primary key and if it is assigned to a combination of columns it is said to be a composite pirmary key, which can contain a maximum of 16 columns.

  Was this answer useful?  Yes

shiiva

  • Feb 4th, 2011
 

One table can have only one Primary Key !!

That one primary key can be either on single column i.e. general Primary Key
Or on multiple columns i.e. Composite Primary key

Example : General PK
Alter table Add constraint pk_emp PRIMARY KEY ON (empno):

Composit PK :
Alter table Add constraint pk_emp PRIMARY KEY ON (empno, deptno, sal)

Shiv

  Was this answer useful?  Yes

Table can have only one primary key in column level.
In table level using composite primary key , table can have maximum 32 primary key columns.
We want to another primary key column in column level....we can assign Unique+Not Null constarints for column.
Means Primary key is combination of Unique and NotNull. so we can assign these two for columns.

  Was this answer useful?  Yes

Yes, a primary key may contain more than one columns.
It allows different combinations of column-values.

syntax may be like:
constraint primary key(column1, column2,......);

  Was this answer useful?  Yes

Payal

  • Aug 24th, 2011
 

Yes a primary key can contain more than one column.

Example:
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)
)

Note: In the example above there is only ONE PRIMARY KEY (pk_PersonID). However, the value of the pk_PersonID is made up of two columns (P_Id and LastName).

  Was this answer useful?  Yes

vijay

  • Aug 25th, 2011
 

it contain only one primary key to one column .if wanted more primary keys in the table ,we have to initialize at the creation of table with parentheses

  Was this answer useful?  Yes

Yasodha

  • Aug 29th, 2011
 

there will be only one primary key.but there may be more than one foregin key.

  Was this answer useful?  Yes

Yes, a table can have only one primary key and a primary key can have more than one column. This primary key is known as composite primary key

  Was this answer useful?  Yes

sukhanand dudhbhate

  • Sep 16th, 2011
 

Yes,primary key can have more than one column and that concept is called as composite/primary

" Alter table employee add constraints emp_pk primary key(employee_id,phone_no); "

---it will work on oracle 10g.

Code
  1. <br />Alter TABLE employee ADD constraints emp_pk PRIMARY KEY(employee_id,phone_no);                                               ---it will work on oracle 10g.

  Was this answer useful?  Yes

venky

  • Sep 22nd, 2011
 

in some situations...
if the selected primary key column contains unique row elements..
need only one column....
if it contains any duplicates...then we take two columns

  Was this answer useful?  Yes

Yes, a primary key can contain more than one one column.
Per EF Cobb's definition, a primary key is the sole candidate key on a relation variable (table) formed from one or more attribute values (columns), which do not contain NULL values, that uniquely identifies a tuple (row) within the relation variable (table).
The ANSI SQL Standards define the creation of a primary key for a table as follows:

Code
  1. ALTER TABLE <TABLE identifier>

  2.     ADD [ CONSTRAINT <CONSTRAINT identifier> ]

  3.     PRIMARY KEY ( <COLUMN expression> {, <COLUMN expression>}... )

  4.  

The per the ANSI SQL Standards the conditions for Primary Keys are:
Only one primary key per table
Primary keys may consist of one or multiple columns
The column or columns forming a primary key may not contain NULL values

  Was this answer useful?  Yes

Suresh Babu Nallamothu

  • Nov 8th, 2018
 

No,Because only one primary key is available for the one table. If you want to use morethan one primary key in a table,it is called as composite primary key.

Code
  1.  

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions