1️⃣ What is SQL and its types?
SQL (Structured Query Language) is used to manage and manipulate databases.
Types: DDL, DML, DCL, TCL
Example:
CREATE, SELECT, GRANT, COMMIT2️⃣ Explain SQL constraints.
Constraints ensure data integrity:
⦁ PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK
3️⃣ What is normalization?
It's organizing data to reduce redundancy and improve integrity (1NF, 2NF, 3NF…).
4️⃣ Explain different types of JOINs with example.
⦁ INNER JOIN: Returns matching rows
⦁ LEFT JOIN: All from left + matching right rows
⦁ RIGHT JOIN: All from right + matching left rows
⦁ FULL JOIN: All rows from both tables
5️⃣ What is a subquery? Give example.
A query inside another query:
SELECT name FROM employees
WHERE department_id = (SELECT id FROM departments WHERE name='Sales');
6️⃣ How to optimize slow queries?
Use indexes, avoid SELECT *, use joins wisely, reduce nested queries.
7️⃣ What are aggregate functions? List examples.
Functions that perform a calculation on a set of values:
SUM(), COUNT(), AVG(), MIN(), MAX()8️⃣ Explain SQL injection and prevention.
A security vulnerability to manipulate queries. Prevent via parameterized queries, input validation.
9️⃣ How to find Nth highest salary without TOP/LIMIT?
SELECT DISTINCT salary FROM employees e1
WHERE N-1 = (SELECT COUNT(DISTINCT salary) FROM employees e2 WHERE e2.salary > e1.salary);
🔟 What is a stored procedure?
A precompiled SQL program that can be executed to perform operations repeatedly.
🔥 React for more! ❤️