11. What is a subquery? Give an example.
A subquery is a query nested inside another query (SELECT, INSERT, UPDATE, DELETE). It helps filter or calculate values dynamically.Example:
12. Explain the concept of normalization.
Normalization is organizing data to minimize redundancy by dividing tables and defining relationships using keys. It improves data integrity and reduces update anomalies. Common normal forms: 1NF, 2NF, 3NF.
13. What is denormalization? When is it used?
Denormalization is combining tables to reduce joins, improving read performance at the cost of redundancy. Used in data warehousing or OLAP scenarios requiring fast query responses.
14. Describe transactions and their properties (ACID).
A transaction is a set of SQL operations treated as a single unit. ACID properties:
⦁ Atomicity: all or nothing execution
⦁ Consistency: database moves from one valid state to another
⦁ Isolation: concurrent transactions don’t interfere
⦁ Durability: changes persist after commit
15. What is a stored procedure?
A stored procedure is a precompiled SQL program stored in the database, which can accept parameters and perform complex operations efficiently, improving performance and reusability.
16. How do you handle NULL values in SQL?
Use
IS NULL or IS NOT NULL to check NULLs. Functions like COALESCE() or IFNULL() replace NULLs with specified values in queries.17. Explain the difference between UNION and UNION ALL.
⦁ UNION combines results of two queries and removes duplicates.
⦁ UNION ALL combines results including duplicates, faster than UNION.
18. What are views? How are they useful?
A view is a virtual table based on a SELECT query. It simplifies complex queries, provides security by restricting access, and allows data abstraction.
19. What is a trigger? Give use cases.
Triggers are special procedures that automatically execute in response to certain events on a table (e.g., INSERT, UPDATE). Use cases: auditing changes, enforcing business rules, cascading changes.
20. How do you perform aggregate functions in SQL?
Aggregate functions process multiple rows to return a single value, e.g.,
COUNT(), SUM(), AVG(), MIN(), and MAX(). Often used with GROUP BY to group results.
No comments:
Post a Comment