كيز2
كيز2
Candidate Key
Primary Key
Super Key
Alternate Key
Foreign Key
Composite Key
Candidate Key
The minimal set of attributes that can uniquely identify a tuple is known as a candidate key. For Example,
STUD_NO in STUDENT relation.
A table can have multiple candidate keys but only one primary key.
The value of the Candidate Key is unique and may be null for a tuple.
Example:
Table STUDENT
The candidate key can be simple (having only one attribute) or composite as well.
Example:
Table STUDENT_COURSE
TEACHER_N
STUD_NO O COURSE_NO
1 001 C001
2 056 C005
Note: In SQL Server a unique constraint that has a nullable column, allows the value ‘ null ‘ in that
column only once . That’s why the STUD_PHONE attribute is a candidate here, but can not be a ‘null’
value in the primary key attribute.
Primary Key
There can be more than one candidate key in relation out of which one can be chosen as the primary
key. For Example, STUD_NO, as well as STUD_PHONE, are candidate keys for relation STUDENT but
STUD_NO can be chosen as the primary key (only one out of many candidate keys).
It is a unique key.
It cannot be NULL.
Primary keys are not necessarily to be a single column; more than one column can also be a
primary key for a table.
Example:
Super Key
The set of attributes that can uniquely identify a tuple is known as Super Key. For Example, STUD_NO,
(STUD_NO, STUD_NAME), etc. A super key is a group of single or multiple keys that identifies rows in a
table. It supports NULL values.
Adding zero or more attributes to the candidate key generates the super key.
Example:
Alternate Key
The candidate key other than the primary key is called an alternate key .
All the keys which are not primary keys are called alternate keys.
It is a secondary key.
Example:
Foreign Key
If an attribute can only take the values which are present as values of some other attribute, it will be
a foreign key to the attribute to which it refers. The relation which is being referenced is called
referenced relation and the corresponding attribute is called referenced attribute. The referenced
attribute of the referenced relation should be the primary key to it.
It is a key it acts as a primary key in one table and it acts as
secondary key in another table.
For example, DNO is a primary key in the DEPT table and a non-key in EMP
Example:
Table STUDENT_COURSE
TEACHER_N
STUD_NO O COURSE_NO
1 005 C001
2 056 C005
It may be worth noting that, unlike the Primary Key of any given relation, Foreign Key can be NULL as
well as may contain duplicate tuples i.e. it need not follow uniqueness constraint. For Example,
STUD_NO in the STUDENT_COURSE relation is not unique. It has been repeated for the first and third
tuples. However, the STUD_NO in STUDENT relation is a primary key and it needs to be always unique,
and it cannot be null.
Relation between Primary Key and Foreign Key
Composite Key
Sometimes, a table might not have a single column/attribute that uniquely identifies all the records of a
table. To uniquely identify rows of a table, a combination of two or more columns/attributes can be
used. It still can give duplicate values in rare cases. So, we need to find the optimal set of attributes that
can uniquely identify rows in a table.
Different combinations of attributes may give different accuracy in terms of identifying the rows
uniquely.
Example:
Conclusion
In conclusion, the relational model makes use of a number of keys: Candidate keys allow for distinct
identification, the Primary key serves as the chosen identifier, Alternate keys offer other choices, and
Foreign keys create vital linkages that guarantee data integrity between tables. The creation of strong
and effective relational databases requires the thoughtful application of these keys.
Answer:
Keys are one of the important aspects of DBMS. Keys help us to find the tuples(rows) uniquely in the
table. It is also used in developing various relations amongst columns or tables of the database.
Answer:
Unique Keys are the keys that define the record uniquely in the table. It is different from Primary Keys, as
Unique Key can contain one NULL value but Primary Key does not contain any NULL values.
Answer:
Artificial Keys are the keys that are used when no attributes contain all the properties of the Primary Key
or if the Primary key is very large and complex.
Get ready to boost your rank and secure an exceptional GATE 2025 score with confidence!
Our GATE CS & IT Test Series 2025 offers 60 PYQs Quizzes, 60 Subject-Wise Mock Tests, 4500+
PYQs and practice questions, and over 20 Full-Length Mock Tests that ensure you’re well-prepared to
tackle the toughest questions and secure a top-rank in the GATE 2025 exam. Get personalized insights
with student rankings based on performance and benefit from expert-designed tests created by industry
pros and GATE CS toppers.