Geeks Talk

Prepare for your Next Interview




Primary key & foreign key

This is a discussion on Primary key & foreign key within the Oracle forums, part of the Databases category; Plz tell me with example the difference between Primary key,foreign key,unique key...


Go Back   Geeks Talk > Databases > Oracle

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 06-13-2008
Junior Member
 
Join Date: Jun 2008
Location: New delhi
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
amitdba08 is on a distinguished road
Primary key & foreign key

Plz tell me with example the difference between Primary key,foreign key,unique key
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-13-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: Primary key & foreign key

Unique Key prohibits multiple rows from having the same value in the same column or combination of columns . But it allows null values.

Primary key is a combination of UNIQUE KEY and NOT NULL. It will not allow duplicate values and null values.

Foreign key ensures conformity between two tables. If a column is defined as foreign key it can contain only values from a parent table's primary key or a unique key.

For examples follow the link
Reply With Quote
  #3 (permalink)  
Old 06-13-2008
Moderator
 
Join Date: Jun 2007
Location: Bangalore,India
Posts: 1,432
Thanks: 8
Thanked 125 Times in 112 Posts
debasisdas will become famous soon enoughdebasisdas will become famous soon enough
Re: Primary key & foreign key

Primary key---------enforces both uniqueness and not null(no duplicate and no null in the column)
foreign key----------maintains referential integrity(child record refers to parent record)
unique key----------maintains uniqueness of data in the column(no duplicate records)
Reply With Quote
  #4 (permalink)  
Old 06-24-2008
Junior Member
 
Join Date: Jun 2008
Location: mumbai
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
sumit palkar is on a distinguished road
Re: Primary key & foreign key

primary key not accept null value & it is related with unique table while foreign
key is related with more than one table with one simillar coloumn.
Reply With Quote
The Following User Says Thank You to sumit palkar For This Useful Post:
  #5 (permalink)  
Old 06-24-2008
Junior Member
 
Join Date: Jun 2008
Location: pune
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
xx_vd is on a distinguished road
Re: Primary key & foreign key

Quote:
Originally Posted by amitdba08 View Post
Plz tell me with example the difference between Primary key,foreign key,unique key

primary key is key to identify uniqe record,is not null,unique,dont allow duplicate

foreign kay is key which act as primary key in one table & foreign key in another table
it is reference bet two table

unique key is same as primary key
Reply With Quote
  #6 (permalink)  
Old 06-24-2008
Junior Member
 
Join Date: Jun 2008
Location: INDIA
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vermar is on a distinguished road
Re: Primary key & foreign key

just to add here unique key can contain null value, while primary key can not contain null value.
Reply With Quote
  #7 (permalink)  
Old 06-24-2008
Junior Member
 
Join Date: Jun 2008
Location: hyderabad
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
shasi1986 is on a distinguished road
Re: Primary key & foreign key

primary key is combination of both unique and notnull keys.
unique key is a key which is not accept any duplication.
foriegn key is a key which is act as a primary key to some other table.
Reply With Quote
  #8 (permalink)  
Old 10-06-2008
Junior Member
 
Join Date: Oct 2008
Location: AHMEDABAD
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
sunshine60india is on a distinguished road
Thumbs up Re: Primary key & foreign key

Set of fields in database taken collectively to identify any row uniquely is called Candidate key...
So Database has more than 1 Candidate key...

Primary key is the Candidate key choosen by the Database Designer...

Unique Key is the constraint that is used to insert unique value in the field of the database...
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
DateTime as Primary Key? icepack2000 Oracle 1 04-22-2008 07:59 AM
Primary Key References krishnaindia2007 Oracle 1 03-06-2008 07:38 AM
Different data type for primary and foreign keys Geek_Guest SQL 3 11-28-2007 04:45 AM
Is foreign university is better to apply Geek_Guest Career Advice 1 09-29-2007 02:42 AM
To handle foreign characters janelyn Web Design 0 08-03-2006 04:08 PM


All times are GMT -4. The time now is 02:49 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved