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: 4If AB and C are the candidate keys in a relational schema R(A,B,C,D), then what are the prime attributes?
Option A
In a Relational Database, a Candidate Key is the minimum set of attribute(s) that can uniquely identify each tuple (row) in a relation.
A relation may have more than one candidate key, but only one of them is selected as the Primary Key.
In the given relation R(A, B, C, D), the candidate keys are AB and C.
Hence, the Prime Attributes are A, B, and C.
| Candidate Key | Prime Attribute | Non-Prime Attribute |
|---|---|---|
| The minimum set of attribute(s) that uniquely identifies each tuple in a relation. | An attribute that belongs to at least one Candidate Key. | An attribute that does not belong to any Candidate Key. |
Q: 5Key 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: 6Which 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: 7Let 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: 8Let 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: 9How 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: 10Consider 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.
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.