in Databases retagged by
2,756 views
2 votes
2 votes
A foreign key can refer to columns in another table, that are

A. Primary key only

B. Candidate key only

C. Unique column only.

D. Foreign key can refer any column
in Databases retagged by
by
2.8k views

3 Answers

5 votes
5 votes
A foreign key can refer to columns in another table, that are Primary key only.

In a foreign key reference, a link is created between two tables when the column or columns that hold the primary key value for one table are referenced by the column or columns in another table. This column becomes a foreign key in the second table.

Candidate keys also used if primary key is not present.

Best answer here is candidate key which is unique
edited by

4 Comments

shiva candidte can contain null .

primary key is s[pecial case of candidate keys i.e. when not contain null.
1
1

Candidate key cannot be null..
It is very much equivalent to primary key.
http://www.geekinterview.com/question_details/47276

I think suppose, C1 C2 C3 are three avilable candidate keys, Database administrator can decide one of them as primary key

eg: Choose C1 as primary key.

0
0

I thinkanswer is B. Candidate Key

According to wikipedia

https://en.wikipedia.org/wiki/Referential_integrity

any field in a table that is declared a foreign key can contain either a null value, or only values from a parent table's primary key or a candidate key

Since a primary key is also a candidate key of that relation, answer must be B

0
0
0 votes
0 votes

I think answer is B. Candidate Key

According to wikipedia

https://en.wikipedia.org/wiki/Referential_integrity

any field in a table that is declared a foreign key can contain either a null value, or only values from a parent table's primary key or a candidate key

Since a primary key is also a candidate key of that relation, answer must be B

edited by
by

2 Comments

For the same reason then why not "unique key". Also, I don't know in theory unique key is there in SQL.

The whole restriction of foreign key is that the values in child table can come only from the parent table. Like manager being an employee in an office implies, managerid must come from set of employeeid values. When a manager employee resigns, the manager table entry also becomes invalid. So, it should be A, B and C and "only" should make C the answer.

Even D is possible as in MYSQL, but the issue is when parent table entry is having duplicates, when an entry is deleted from parent table, we cannot simply delete the same (delete on cascade) from child table.
0
0
@Arjun sir...So what is the most appropriate answer?
0
0
0 votes
0 votes
It can refer primary key or alternate key of same reln or other reln