CIW CIW Database Design & SQL 1 — Questions and Answers
Question 1: What is the purpose of a primary key in a relational database table?
- To uniquely identify each row in the table (Correct answer)
- To link two tables with a foreign key relationship
- To define the default value for a column
- To index every column for faster queries
Correct answer: To uniquely identify each row in the table
A primary key is a column or combination of columns whose values uniquely identify every row, preventing duplicate records.
Question 2: Which SQL command is used to retrieve data from a database table?
- SELECT (Correct answer)
- INSERT
- UPDATE
- DELETE
Correct answer: SELECT
The SELECT statement queries one or more tables and returns a result set matching the specified columns and conditions.
Question 3: What does normalization achieve in database design?
- Reduces data redundancy and ensures data integrity by organizing tables logically (Correct answer)
- Increases the number of tables to speed up queries
- Encrypts sensitive columns automatically
- Merges all related data into a single flat table
Correct answer: Reduces data redundancy and ensures data integrity by organizing tables logically
Normalization organizes database tables to minimize redundancy and dependency, typically following normal forms (1NF, 2NF, 3NF).
Question 4: What is a foreign key in a relational database?
- A column that references the primary key of another table to establish a relationship (Correct answer)
- A secondary index on a frequently queried column
- An encrypted key used to access the database
- A backup copy of the primary key stored in a separate table
Correct answer: A column that references the primary key of another table to establish a relationship
A foreign key enforces referential integrity by ensuring that a value in one table matches an existing value in the referenced table's primary key.
Question 5: Which SQL clause is used to filter query results based on a condition?
- WHERE (Correct answer)
- GROUP BY
- ORDER BY
- HAVING
Correct answer: WHERE
The WHERE clause filters rows before any grouping or aggregation occurs, returning only records that meet the specified condition.
Question 6: What type of SQL JOIN returns only rows that have matching values in both tables?
- INNER JOIN (Correct answer)
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN
Correct answer: INNER JOIN
An INNER JOIN returns only the rows where the join condition is satisfied in both tables, excluding unmatched rows from either side.
What is the purpose of a primary key in a relational database table?