This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1An ________ is a field or a combination of fields that can be used to access or retrieve records from a table.
Option B
A Secondary Key is a field or a group of fields that is used to retrieve or search records in a table but does not uniquely identify a record.
For example, in a student table, attributes like name or city can be used as secondary keys to retrieve multiple matching records.
Q: 2In Database Management System (DBMS), consider the following statements and choose the correct answer.
(I) The value of an attribute can be NULL.
(II) Primary key helps to find out all other attributes.
Option C
In DBMS, an attribute can have a NULL value unless it is specifically restricted using constraints like NOT NULL. NULL means the value is unknown, missing, or not applicable.
A Primary Key uniquely identifies each record in a relation. Since the primary key uniquely identifies a row, it can be used to retrieve all other attributes of that row.
Q: 3In context of a relational database, choose a false statement :
Option D
In a relational database, a Super Key is any set of attributes that uniquely identifies tuples, but it may contain extra attributes and hence is not always minimal.
A Candidate Key is a minimal super key, meaning no subset of it can be a super key. Among candidate keys, one is chosen as the Primary Key to uniquely identify tuples.
Since the Primary Key itself is a candidate key, it cannot be a proper subset of another candidate key.
| KEY TYPE | DESCRIPTION |
|---|---|
| Super Key | A set of one or more attributes that uniquely identifies a tuple in a relation. It may contain extra attributes. |
| Candidate Key | A minimal super key, i.e., a super key with no unnecessary attributes. Each relation can have one or more candidate keys. |
| Primary Key | A candidate key chosen by the database designer to uniquely identify tuples in a relation. Must not contain NULL. |
| Alternate Key | Any candidate key that is not selected as the primary key. |
| Foreign Key | An attribute in one table that refers to the primary key of another table to maintain referential integrity. |
| Composite Key | A key that consists of two or more attributes to uniquely identify a tuple. |
| Partial Key | Used in weak entity sets to uniquely identify tuples only when combined with the primary key of the identifying entity. |
Q: 4Key to represent the relationship between tables is called __________.
Option C
In a relational database, a Foreign Key is used to establish a relationship between two tables. It is a field in one table that refers to the Primary Key of another table, ensuring data consistency and integrity.
For example, if a Student table has rollno as a primary key, then another table like Marks can use rollno as a foreign key to link records between the two tables.
| KEY TYPE | PURPOSE |
|---|---|
| Primary Key | Uniquely identifies a record in a table. |
| Foreign Key | Links two tables together. |
| Secondary Key | Used for searching, not for relationships. |
Q: 5Which of the following is a column constraint in SQL?
Option D
A column constraint is applied directly to a single column while defining a table.
Q: 6Let R(a,b,c) and S(d,e,f) be two relations in which d is the foreign key of S that refers to the primary key c of R
Consider the following four operations
1. Insert into R
2. Delete from S
3. Insert into S
4. Delete from R
Which of the following can cause violation of referential integrity constraint above?
Option A
Referential Integrity ensures that a foreign key in one table must match a primary key in another table or be NULL. Here:
| Operation | Effect | Violation? | Explanation |
|---|---|---|---|
| Insert into R | Adds new primary key | No | Does not affect existing foreign keys. |
| Delete from S | Removes foreign key entries | No | No dependency issue. |
| Insert into S | Adds foreign key value | Yes | If inserted value not present in R(c), violation occurs. |
| Delete from R | Removes primary key | Yes | If referenced by S(d), causes violation. |
Q: 7Let relation R2 has a 'foreign key' that refers to the primary key of relation R1. Which of the following operation may cause violation of referential integrity constraints?
Option C
Referential integrity constraint ensures that a Foreign Key in one relation (R2) must always refer to an existing Primary Key in another relation (R1).
If we insert a tuple in R2 with a foreign key value that does not exist as a primary key in R1, it violates referential integrity.
If a tuple in R1 is deleted but there are still tuples in R2 that reference it, the relationship becomes invalid, causing a referential integrity violation.
| Operation | Reason for Violation | Possible SQL Solutions |
|---|---|---|
| Insertion in R2 | Foreign key in R2 points to a non-existent primary key in R1. |
|
| Deletion from R1 | R2 has orphan references after deletion in R1. |
|
| Update in R1 | Violation occurs because foreign key values in R2 no longer match R1. |
|
| Update in R2 | Violation occurs because foreign key values in R2 no longer match R1. |
|
Q: 8How many primary keys can a table have?
Option A
A table can have only one primary key. The primary key uniquely identifies each record in a table.
It may consist of one attribute or a combination of multiple attributes (composite primary key).
Q: 9Consider the following statements regarding key-
(I) A super key is an attribute or combination of attributes that uniquely identifies records in a RDBMS table.
(II) A candidate key is a subset of a super key.
(III) All super keys are candidate keys but vice versa is not true.
Option D
In a Relational Database Management System (RDBMS), keys are used to uniquely identify records in a table or relation. A super key is an attribute or a combination of attributes that ensures the uniqueness of each record. Among these super keys, a candidate key is a minimal set of attributes that can still uniquely identify a record, meaning it does not contain any unnecessary attributes.
In other words, every candidate key is a subset of a super key, but not all super keys are candidate keys because some may include extra attributes that are not needed for uniqueness.
Q: 10Which integrity rule ensures that a foreign key value in one table must match an existing primary key value in another related table?
Option A
Referential Integrity means that you cannot enter a value in a foreign key column unless that value already exists as a primary key in another table. This rule ensures that the relationship between tables remains valid and consistent.
E.g.:
CREATE TABLE Student
(
RollNo INT PRIMARY KEY,
Name VARCHAR(50)
);
The RollNo is the primary key of the Student table.
CREATE TABLE Course
(
CourseNo INT PRIMARY KEY,
RollNo INT,
FOREIGN KEY (RollNo) REFERENCES Student(RollNo)
);
The CourseNo is the primary key of the Course table and RollNo is a foreign key that refers to Student(RollNo).
INSERT INTO Student VALUES (101, 'Suresh Kulahry'); /* Valid (Allowed) */
INSERT INTO Course VALUES (201, 101); /* Valid (Allowed) */
INSERT INTO Course VALUES (202, 105); /* Invalid (Not Allowed) */
Q: 11Which of the following is TRUE?
Option A
A key is one or more attributes (columns) used to identify records uniquely or to establish relationships between tables in a relational database.
There are different types of keys in DBMS, such as Super Key, Candidate Key, Primary Key, Alternate Key, and Foreign Key. Each key has a specific purpose.
A Foreign Key is an attribute (or a set of attributes) in one table that refers to the Primary Key (or Candidate Key) of another table. It is used to establish and maintain a relationship between two tables.
A table can have multiple foreign keys if it references multiple tables or references the same table more than once.
| Key Type | Purpose |
|---|---|
| Super Key | Uniquely identifies each record; may contain extra attributes. |
| Candidate Key | Minimal super key that uniquely identifies each record. |
| Primary Key | Selected candidate key used as the main identifier. |
| Alternate Key | Candidate keys that are not selected as the Primary Key. |
| Foreign Key | Establishes a relationship between two tables by referring to the Primary (or Candidate) Key of another table. |
Q: 12Which of the following is FALSE?
Option D
A Super Key is any set of one or more attributes that uniquely identifies each record in a table. It may contain unnecessary (redundant) attributes.
A Candidate Key is a Minimal Super Key, meaning no attribute can be removed without losing uniqueness.
Hence, only Candidate Keys satisfy the minimality condition, not Super Keys.
Q: 13In relational database minimal super keys is known as-
Option C
A super key is a set of one or more attributes that uniquely identify each record in a table. However, a super key may include extra attributes that are not necessary for uniqueness.
When we remove all unnecessary attributes from a super key, leaving the minimal set of attributes that still uniquely identify each record, it becomes a candidate key.
Every candidate key is a minimal super key, meaning it cannot be reduced any further without losing the ability to uniquely identify records. From among the candidate keys, one is selected as the primary key to uniquely identify rows in the table.
Q: 14The purpose of foreign key in a table is to ensure
Option D
A Foreign Key is used to create a relationship between two tables. Its main purpose is to ensure Referential Integrity, which means that the value in the foreign key column must match a value in the primary key of the referenced table or be NULL, if allowed.
This ensures that there are no invalid or orphan records in the database.
Q: 15Consider a relation R with attributes (A, B, C), where B is the only candidate key. Identify the total number of possible super keys of the relation R.
Option C
A superkey is any set of attributes that can uniquely identify a tuple in a relation. If you have a relation with n attributes and one candidate key consisting of k attributes, the total number of super keys is 2n−k.
Remember, this formula can only work with a relation has only one candidate key consisting of k attributes.
Given,
Relation: R(A, B, C)
Total Attributes (A,B,C) n = 3.
Candidate key B : k = 1
Total super keys: 23−1 = 22 = 4.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.