21. Which SQL statement is used to add new records?
- a) INSERT
- b) ADD
- c) CREATE
- d) UPDATE
Answer: A - INSERT INTO adds new rows to a table.
22. What is the purpose of a PRIMARY KEY?
- a) Uniquely identifies each record
- b) Speeds up queries
- c) Links tables together
- d) All of the above
Answer: D - Primary keys uniquely identify rows, enable joins, and improve performance.
23. Which function returns the current date?
- a) CURDATE()
- b) NOW()
- c) SYSDATE()
- d) All of the above
Answer: D - All these functions return date/time (varies by DBMS).
24. What does the COMMIT statement do?
- a) Saves transaction changes permanently
- b) Deletes all records
- c) Creates a backup
- d) Exits the database
Answer: A - COMMIT finalizes transactions.
25. Which operator combines multiple conditions?
- a) AND
- b) OR
- c) NOT
- d) All of the above
Answer: D - Logical operators combine conditions in WHERE clauses.
26. What is the default transaction isolation level in most databases?
- a) READ COMMITTED
- b) READ UNCOMMITTED
- c) REPEATABLE READ
- d) SERIALIZABLE
Answer: A - READ COMMITTED prevents dirty reads (common default).
27. Which statement alters a table's structure?
- a) ALTER TABLE
- b) MODIFY TABLE
- c) UPDATE TABLE
- d) CHANGE TABLE
Answer: A - ALTER TABLE adds/drops/modifies columns.
28. What does the NVL() function do in Oracle?
- a) Replaces NULL with a specified value
- b) Counts non-null values
- c) Validates data types
- d) Encrypts data
Answer: A - NVL(expr1, expr2) returns expr2 if expr1 is NULL.
29. Which join returns only matched records?
- a) INNER JOIN
- b) LEFT JOIN
- c) FULL JOIN
- d) CROSS JOIN
Answer: A - INNER JOIN returns only rows with matches in both tables.
30. What is a self-join?
- a) Joining a table to itself
- b) Combining all columns
- c) Automatic index creation
- d) Recursive query
Answer: A - Self-joins compare rows within the same table (e.g., employee-manager relationships).
31. Which clause limits the number of returned rows?
- a) LIMIT
- b) TOP
- c) FETCH FIRST
- d) All of the above
Answer: D - Syntax varies by DBMS (MySQL: LIMIT, SQL Server: TOP, Oracle: FETCH FIRST).
32. What is database normalization?
- a) Minimizing redundancy
- b) Speeding up queries
- c) Organizing data efficiently
- d) All of the above
Answer: D - Normalization structures data to reduce duplication and improve integrity.
33. Which SQL function extracts part of a string?
- a) SUBSTRING()
- b) LEFT()
- c) RIGHT()
- d) All of the above
Answer: D - All these functions extract portions of strings.
34. What is a cursor in SQL?
- a) Pointer to traverse result sets
- b) Encryption tool
- c) Backup mechanism
- d) Index type
Answer: A - Cursors allow row-by-row processing of query results.
35. Which statement creates a database view?
- a) CREATE VIEW
- b) MAKE VIEW
- c) DEFINE VIEW
- d) ALTER VIEW
Answer: A - CREATE VIEW view_name AS SELECT... defines a virtual table.
36. What is the purpose of the WITH clause?
- a) Defines a Common Table Expression (CTE)
- b) Filters groups
- c) Creates temporary tables
- d) Encrypts queries
Answer: A - WITH creates named temporary result sets usable in a query.
37. Which constraint ensures referential integrity?
- a) FOREIGN KEY
- b) CHECK
- c) UNIQUE
- d) NOT NULL
Answer: A - Foreign keys link tables and enforce valid references.
38. What does the EXPLAIN statement do?
- a) Shows query execution plan
- b) Describes table structure
- c) Exports data
- d) Validates SQL syntax
Answer: A - EXPLAIN helps optimize queries by revealing how they'll execute.
39. Which function rounds a number to decimals?
- a) ROUND()
- b) TRUNCATE()
- c) FLOOR()
- d) CEIL()
Answer: A - ROUND(number, decimals) rounds to specified decimal places.
40. What is a stored procedure?
- a) Precompiled SQL code block
- b) Backup file
- c) Temporary table
- d) Index type
Answer: A - Stored procedures encapsulate reusable database logic.