SQL Questions and Answers : PART 1

1. What is denormalization?
A. Removing tables
B. Combining tables to improve performance
C. Deleting duplicate data
D. Creating indexes only
Ans : B

2. What is the main advantage of denormalization?
A. Less storage
B. Better normalization
C. No redundancy
D. Faster query performance
ANS : D

3. What is a disadvantage of denormalization?
A. Increased redundancy
B. Better reporting
C. Reduced JOINs
D. Faster queries
Ans : A

4. Which systems commonly use denormalization?
A. Banking transaction systems
B. Reporting and dashboard systems
C. Authentication systems
D. Compiler systems
Ans : B

5. Which statement is TRUE?
A. Normalization improves performance only
B. Denormalization reduces redundancy
C. Normalization reduces redundancy
D. Denormalization removes duplicate data
Ans : C

6. What is the purpose of constraints in SQL?
A. Increase redundancy
B. Maintain data integrity
C. Speed up internet
D. Delete tables
Ans : B

7. Which constraint prevents NULL values?
A. DEFAULT
B. UNIQUE
C. NOT NULL
D. CHECK
Ans : C

8. Which constraint ensures all values are unique?
A. PRIMARY KEY
B. FOREIGN KEY
C. DEFAULT
D. UNIQUE
Ans : D

9. What is the main purpose of a FOREIGN KEY?
A. Create duplicate values
B. Improve UI design
C. Create relationship between table
D. Delete records automatically
Ans : C

10. Which constraint is used to restrict values based on condition?
A. UNIQUE
B. CHECK
C. DEFAULT
D. NOT NULL
Ans : B

11. What is the purpose of UNION in SQL?
A. Delete duplicate rows
B. Combine results of multiple SELECT queries
C. Create relationships
D. Sort tables
Ans : B

12. What does UNION do with duplicate rows?
A. Keeps duplicates
B. Deletes table
C. Removes duplicates
D. Converts to NULL
Ans : C

13. Which operator keeps duplicate rows?
A. UNION
B. UNION DISTINCT
C. UNION ALL
D. JOIN
Ans : C

14. Which statement is TRUE about UNION?
A. Number of columns can be different
B. Column data types should be compatible
C. ORDER BY cannot be used
D. UNION works only on one table
Ans : B

15. Which is faster for large datasets?
A. GROUP BY
B. JOIN
C. UNION
D. UNION ALL
Ans : A

16. What is the purpose of CASE statement in SQL?
A. Apply conditional logic
B. Join tables
C. Delete rows
D. Create tables
Ans : A

17. CASE statement in SQL is similar to which programming concept?
A. Loop
B. Function
C. if-else
D. Array
Ans : C

18. Which keyword is mandatory in CASE statement?
A. BREAK
B. END
C. STOP
D. EXIT
Ans : B

19. CASE statement is commonly used in:
A. Reporting and dashboards
B. Game development only
C. Hardware design
D. Network routing
Ans : A

20. What does NULL represent in SQL?
A. Zero
B. Empty string
C. Missing or unknown value
D. False value
Ans : C

21. What is the purpose of COALESCE function?
A. Delete NULL values
B. Replace NULL with another value
C. Sort NULL values
D. Count NULL values
Ans : B

22. What will this query return if bonus is NULL?
SELECT COALESCE(bonus, 0) FROM employees;
A. NULL
B. 0
C. bonus
D. Empty string
Ans : B

23. What does COALESCE(phone, email, 'No Contact') return?
A. Last value always
B. First non-NULL value
C. Only NULL values
D. Nothing
Ans : B

24. Which function converts text to uppercase?
A. LOWER()
B. UPPER()
C. CAPITAL()
D. CASE()
Ans : B

25. What does CONCAT() do in SQL?
A. Removes spaces
B. Counts characters
C. Combines strings
D. Extracts substring
Ans : C

26. Which function removes extra spaces from text?
A. REPLACE()
B. LENGTH()
C. CONCAT()
D. TRIM()
Ans : D

27. What will this query return?
SELECT REPLACE('I love Java', 'Java', 'SQL');
A. I love Java
B. I love SQL
C. SQL and Java Love
D. SQL
Ans : B

28. Which function returns the current date and time?
A. CURDATE()
B. CURTIME()
C. NOW()
D. DATE()
Ans : C

29. Which function returns only the current date?
A. NOW()
B. CURDATE()
C. TODAY()
D. CURRENT_DATE()
Ans : B

30. Which function is used to calculate difference between two dates?
A. DATE_FORMAT()
B. MONTH()
C. DATEDIFF()
D. DAY()
Ans : C

31. What will this query return?
SELECT DATE_FORMAT('2026-06-28', '%d-%m-%Y');
A. 28-06-2026
B. 06-28-2026
C. 06-28-26
D. 2026-06-28
Ans : A

32. What is a View in SQL?
A. A physical table storing data
B. A virtual table based on a query
C. An index
D. A trigger
Ans : B

33. What is the main difference between a View and a Materialized View?
A. Both store data physically
B. View stores data, Materialized View stores query
C. View stores query, Materialized View stores data
D. There is no difference
Ans : C

34. Which object generally provides faster query performance for large reports?
A. Table Scan
B. View
C. Materialized View
D. Trigger
Ans : C

35. What must be done to see the latest data in a Materialized View after underlying tables change?
A. Recreate the table
B. Refresh the Materialized View
C. Restart the database
D. Create an index
Ans : B

36. Which statement is TRUE?
A. Materialized Views cannot contain aggregate
B. Views always consume more storage than Materialized Views
C. Materialized Views always show real-time data automatically
D. Views always display current data from underlying tables
Ans : D

37. What is a User Defined Function (UDF)?
A. A built-in SQL command
B. A custom function created by users
C. A database table
D. An index
Ans : B

38. What is mandatory for a SQL Function?
A. Must contain JOIN
B. Must return a value
C. Must create a table
D. Must use GROUP BY
Ans : B

39. What is the main difference between a Function and a Procedure?
A. Functions return a value, Procedures may not
B. Procedures return a value, Functions may not
C. Both are identical
D. Functions cannot accept parameters
Ans : A

40. Where can a SQL Function be used?
A. Inside SELECT statement
B. Inside WHERE clause
C. Inside ORDER BY clause
D. All of the above
Ans : D

41. What is a Recursive CTE?
A. A permanent table
B. A CTE that references itself
C. A stored procedure
D. A trigger
Ans : B

42. Which keyword is commonly used to create a Recursive CTE?
A. REPEAT
B. LOOP
C. RECURSIVE
D. FUNCTION
Ans : C

43. What are the two main parts of a Recursive CTE?
A. SELECT and UPDATE
B. Anchor Query and Recursive Query
C. JOIN and GROUP BY
D. WHERE and HAVING
Ans : B

44. What will happen if a Recursive CTE does not have a stopping condition?
A. It will return NULL
B. It will stop automatically after 10 rows
C. It may enter an infinite loop or hit recursion limits
D. It will behave like a normal CTE
Ans : C

45.Which of the following is a common use case for Recursive CTEs?
A. Creating indexes
B. Building employee-manager hierarchies
C. Dropping tables
Ans : B

46. What is Dynamic SQL?
A. SQL stored permanently in a table
B. SQL query built and executed at runtime
C. SQL used only for databases
D. SQL without SELECT statement
Ans : B

47. What is the main advantage of Dynamic SQL?
A. Less flexibility
B. Faster than all queries
C. Flexible query generation at runtime
D. Removes need for indexes
Ans : C

48. Which MySQL statement is used to execute a prepared Dynamic SQL query?
A. RUN
B. EXECUTE
C. CALL
D. START
Ans : B

49. What is a major risk associated with Dynamic SQL?
A. Data normalization
B. Foreign keys
C. Index creation
D. SQL Injection
Ans : D

50. Which statement is TRUE about Static SQL and Dynamic SQL?
A. Static SQL is created at runtime
B. Dynamic SQL is always faster
C. Static SQL is fixed, Dynamic SQL is generated at runtime
D. Both are exactly the same
Ans : C

No comments:

Post a Comment

Infolinks In Text Ads