Cognizant Database Management Systems 1 — Questions and Answers
Question 1: Which of the following best defines a primary key in a relational database?
- A column that can contain NULL values
- A unique identifier for each record in a table (Correct answer)
- A key that references another table
- A key used only for sorting records
Correct answer: A unique identifier for each record in a table
A primary key uniquely identifies each record in a table and cannot contain NULL values.
Question 2: Which SQL clause is used to filter records after a GROUP BY has been applied?
- WHERE
- FILTER
- HAVING (Correct answer)
- ORDER BY
Correct answer: HAVING
HAVING is used to filter groups after GROUP BY, whereas WHERE filters individual rows before grouping.
Question 3: What is the primary goal of database normalization?
- To increase query execution speed
- To eliminate data redundancy and improve data integrity (Correct answer)
- To add more tables to the database
- To allow duplicate records for backup
Correct answer: To eliminate data redundancy and improve data integrity
Normalization organizes data to reduce redundancy and dependency, improving data integrity and storage efficiency.
Question 4: Which type of JOIN returns all rows from both tables, with NULLs where there is no match?
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN (Correct answer)
Correct answer: FULL OUTER JOIN
FULL OUTER JOIN returns all rows from both tables, filling unmatched rows with NULL values.
Question 5: In the context of ACID properties, what does 'Atomicity' mean?
- Data remains consistent before and after a transaction
- A transaction is treated as a single unit — all or nothing (Correct answer)
- Transactions are isolated from each other
- Data is permanently saved after a commit
Correct answer: A transaction is treated as a single unit — all or nothing
Atomicity ensures that all operations in a transaction are completed successfully; if any operation fails, the entire transaction is rolled back.
Question 6: Which SQL command is used to remove a table and all its data permanently from the database?
- DELETE
- TRUNCATE
- DROP (Correct answer)
- REMOVE
Correct answer: DROP
DROP TABLE removes the table definition and all its data permanently, unlike DELETE or TRUNCATE which only remove rows.
Question 7: What is a foreign key?
- A key imported from an external database
- A primary key stored in encrypted form
- A column that references the primary key of another table (Correct answer)
- A unique key shared across multiple tables
Correct answer: A column that references the primary key of another table
A foreign key is a column (or set of columns) in one table that references the primary key of another table, establishing a relationship.
Which of the following best defines a primary key in a relational database?