21. Which SQL command is used to delete a table?
- a) DROP TABLE
- b) DELETE TABLE
- c) REMOVE TABLE
- d) ERASE TABLE
Answer: A - DROP TABLE completely removes a table structure and its data from the database.
22. What is a composite key?
- a) A combination of two or more columns that uniquely identify a row
- b) A key made of composite materials
- c) A primary key that is composed of numbers
- d) A backup of the primary key
Answer: A - A composite key uses multiple columns to uniquely identify a row when no single column is sufficient.
23. Which of the following is NOT a valid SQL constraint?
- a) PRIMARY KEY
- b) FOREIGN KEY
- c) CHECK
- d) VALIDATE
Answer: D - VALIDATE is not a standard SQL constraint (standard constraints are PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, NOT NULL, DEFAULT).
24. What is the purpose of the SQL JOIN clause?
- a) To combine rows from two or more tables based on related columns
- b) To merge two databases into one
- c) To concatenate strings
- d) To create a new table from existing tables
Answer: A - JOIN combines records from two or more tables based on logical relationships between them.
25. Which type of JOIN returns all rows from both tables with NULL in unmatched columns?
- a) FULL OUTER JOIN
- b) INNER JOIN
- c) LEFT JOIN
- d) CROSS JOIN
Answer: A - FULL OUTER JOIN returns all records when there's a match in either left or right table.
26. What is a deadlock in DBMS?
- a) When two or more transactions wait indefinitely for each other to release locks
- b) A corrupted database state
- c) A security breach in the database
- d) When the database server crashes
Answer: A - Deadlock occurs when transactions form a circular wait for resources.
27. Which SQL function returns the number of rows matching a query?
- a) COUNT()
- b) SUM()
- c) TOTAL()
- d) NUMBER()
Answer: A - COUNT() is an aggregate function that returns the number of rows.
28. What is the difference between DELETE and TRUNCATE commands?
- a) DELETE removes specific rows, TRUNCATE removes all rows
- b) DELETE is faster than TRUNCATE
- c) TRUNCATE can be rolled back
- d) DELETE doesn't free table space
Answer: A - DELETE is DML (can have WHERE clause), TRUNCATE is DDL (removes all rows faster but can't be filtered).
29. What is the purpose of the SQL LIKE operator?
- a) To search for a specified pattern in a column
- b) To compare two values
- c) To check if a value is in a list
- d) To perform mathematical operations
Answer: A - LIKE is used in WHERE clauses to search for patterns using wildcards (% and _).
30. Which of the following is NOT a valid type of database relationship?
- a) One-to-One
- b) One-to-Many
- c) Many-to-Many
- d) All-to-None
Answer: D - Standard relationships are One-to-One, One-to-Many, and Many-to-Many.
31. What is the purpose of the SQL UNION operator?
- a) To combine result sets of two or more SELECT statements
- b) To join two tables
- c) To create a union of two databases
- d) To merge columns from different tables
Answer: A - UNION combines results vertically (must have same number of columns).
32. What is a candidate key?
- a) A column or set of columns that could be a primary key
- b) A key used during elections
- c) A temporary key assigned to new records
- d) A foreign key candidate
Answer: A - A candidate key is any field that could serve as a primary key (must be unique and non-null).
33. Which SQL command is used to add a column to an existing table?
- a) ALTER TABLE ADD COLUMN
- b) MODIFY TABLE
- c) UPDATE TABLE
- d) INSERT COLUMN
Answer: A - ALTER TABLE with ADD COLUMN modifies table structure.
34. What is the purpose of the SQL DISTINCT keyword?
- a) To return only unique values
- b) To make queries run faster
- c) To select distinct tables
- d) To filter NULL values
Answer: A - DISTINCT eliminates duplicate rows from the result set.
35. Which of the following is NOT a valid isolation level in SQL?
- a) READ UNCOMMITTED
- b) READ COMMITTED
- c) REPEATABLE READ
- d) READ FAST
Answer: D - Standard isolation levels are READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, and SERIALIZABLE.
36. What is the purpose of the SQL ROLLBACK command?
- a) To undo changes made in the current transaction
- b) To go back to a previous database state
- c) To reverse the last query
- d) To delete the entire database
Answer: A - ROLLBACK undoes all changes since the last COMMIT or ROLLBACK.
37. What is a subquery in SQL?
- a) A query nested inside another query
- b) A backup query
- c) A simplified version of a complex query
- d) A query that runs in the background
Answer: A - A subquery is a SELECT statement inside another SQL statement.
38. Which SQL command is used to change data in a table?
- a) UPDATE
- b) MODIFY
- c) ALTER
- d) CHANGE
Answer: A - UPDATE modifies existing records in a table (DML command).
39. What is the purpose of the SQL ORDER BY clause?
- a) To sort the result set
- b) To organize tables alphabetically
- c) To filter results
- d) To group similar records
Answer: A - ORDER BY sorts results in ascending (ASC) or descending (DESC) order.
40. What is database denormalization?
- a) Intentionally adding redundancy to improve performance
- b) Fixing normalization errors
- c) Removing all constraints from a database
- d) Converting a database to NoSQL
Answer: A - Denormalization strategically introduces redundancy to optimize read performance.