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  >  Tech FAQs  >  RDBMS
Go To First  |  Previous Question  |  Next Question 
 RDBMS  |  Question 12 of 18    Print  
Is it possible to have primary key and foreign key in one table if yes so what is the use of foreign key?

  
Total Answers and Comments: 5 Last Update: November 01, 2007     Asked by: vivek srivastava 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 22, 2006 06:48:03   #1  
neha        

RE: Is it possible to have primary key and foreign key...
yes u can,foreign key is used to cut short the repeated use of primary key data.
 
Is this answer useful? Yes | No
January 09, 2007 01:34:40   #2  
vmshenoy Member Since: October 2005   Contribution: 508    

RE: Is it possible to have primary key and foreign key...
yes , v can have.


Foreign key is used to  make relationship with another table.V can think foreign key as a copy of primary key from another relational table.

 
Is this answer useful? Yes | No
February 22, 2007 21:19:48   #3  
manu        

RE: Is it possible to have primary key and foreign key...
yes it possible 2 have foriegn key constraint on the same table where there is a primary key.this is can done by adding a constraint to the table using alter table tblname . the refernce column and table being the base table.
         thus one table can have both primary key as well as foreign key constraint.

 
Is this answer useful? Yes | No
March 15, 2007 03:59:09   #4  
Nikhil_4_Oracle        

RE: Is it possible to have primary key and foreign key...

Dear All,

Yes its possible.


Alter table reftab add constraint pk_reftab_col1 primary key;


Alter table reftab add constraint fk_reftab_col2 (col2) references reftab (clo1);


it will work....But there is no sence in doing so..u wll just make duplicate data in same table. Also it will increases the data redudancy...

Regards,

Nikhil
 


 
Is this answer useful? Yes | No
November 01, 2007 01:18:07   #5  
Shri        

RE: Is it possible to have primary key and foreign key...
Dear Vivek,
If I understand your question well, you mean to say that "is there any possibility to have both primary & foreign keys in the same table".
Well, the answer is No. The foreign key (by definition) in a table is the key which is the reference of primary key of different table i.e. the foreign key in a table is the primary key of another table. Therefore, in order to make use of foreign key concept, the tables should be different (one containing primary key while other containing foreign key).
(Please let me know for any issues).

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape