GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL

 Print  |  
Question:  What is difference between UNIQUE and PRIMARY KEY constraints?


Answer:
A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.


July 07, 2007 05:20:48 #6
 Faizal   Member Since: Visitor    Total Comments: N/A 

RE: What is difference between UNIQUE and PRIMARY KEY ...
 
/*
Just adding to the Primary Key Explanation
*/

Its right that there can be only one Primary Key for a Table.

But for that Primary Key we can add more than one fields.

Ex:

ALTER TABLE emp ADD CONSTRAINT PRIMARY KEY(emp_no, dept_no, phone);

By the above, all the 3 fields make a combination of a Primary Key.

     

 

Back To Question