ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
can foreign key take role of primary key?
 Question Submitted By :: Ganesh Prasad Sial
I also faced this Question!!     Rank Answer Posted By  
 
  Re: can foreign key take role of primary key?
Answer
# 1
yes but for same table and if you use foriegn key as a 
primary key for same table then there will be no benifit of 
master-detail concept for it relation. 
and if you follow the Master_detail concept then you can't 
use as primary key for another table.
 
Is This Answer Correct ?    5 Yes 1 No
@panwar
 
  Re: can foreign key take role of primary key?
Answer
# 2
No foreign key cant take role of primary key
 
Is This Answer Correct ?    4 Yes 3 No
Kkk
 
 
 
  Re: can foreign key take role of primary key?
Answer
# 3
Yes. This situation occurs in one-to-one relationships.

For example:

    create table Table1
    ( T1_Id    integer     not null primary key
    , T1_Data  varchar(9)  not null
    )
    create table Table2
    ( T2_Id    integer     not null primary key
    , T2_Data  varchar(37) not null
    , foreign key (T2_Id) references Table1 (T1_Id)
    )

Why would someone design two tables like this? If it's a
one-to-one relationship, couldn't you just include T2_Data
in Table1? Yes, you could, although then you would also need
to allow T2_Data to be NULL, if not every T1_Id has a
matching T2_Id—in this case it's actually a
one-to-zero-or-one relationship.

If it's a true one-to-one relationship, where every T1_Id
has a matching T2_Id, then you could combine them without
NULLs. Then the only reason why you might want separate
tables would be if T2_Data were (a) infrequently queried,
and (b) so large that it would result in many fewer physical
rows on a physical database page, which would imply poorer
performance for queries that used only T1_Data.
 
Is This Answer Correct ?    8 Yes 0 No
Gaurav
 
  Re: can foreign key take role of primary key?
Answer
# 4
Yes.  It is possible in this scenario.  Here table has a
self join.  Since emp_id represents both emp_id and mgr_id
this is possible a primary key to behave as foriegn key
create table emp(
emp_id  int not null primarykey,
emp_name varchar2(40) not null,
mgr_id  int not null foriegn key(mgr_id) references emp(emp_id)
}
 
Is This Answer Correct ?    2 Yes 0 No
Suresh Murugadass
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
how to delete duplicate rows from table in sql server HCL8
What are the new features in SQL Server 2005? Emphasis2
Which TCP/IP port does SQL Server run on?  2
when inserting to a table how many rows will be effected using triggers  1
what is web server? Satyam3
How will u find the query which is running in some other machine IBM2
what is the difference between group and having give an example with query and sample output  2
what is the query and condition to delete datas in sql server.  2
Can anybody explain me cold backup and hot backup? TCS3
what are the new features of sql server 2005? HP6
What is deadlock and how to avoid the deadlocks. Wipro3
What are the type of joins? When do we use Outer and Self joins?  3
how insert selected column only ? Robert-Half2
1.what is the difference between view and cursor? 2.If we do any change in view will it affect the database,similarly when we do changes in cursor will it affect the databse?with certain example?Thanks  3
Explain Active/Active and Active/Passive cluster configurations?  1
Lets say due to N/W or Security issues client is not able to connect to server or vice versa. How do you troubleshoot?  1
what are default? Is there a column to which a default cant be bound?  1
can anybody tell us, how to select 2nd max salary from table. my id is ashish.akk@gmail.com Symphony21
How To Make password Protected SQL Server 2005 Database i.e when i open SQL Server database then ask for password.  1
How do you find the error, how can you know the number of rows effected by last SQL statement?  1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com