- Index → improves query speed (like book index).
- Clustered Index → sorts and stores rows physically in table. (Only one allowed).
- Non-Clustered Index → separate structure pointing to data. (Many allowed).
Category: Interview Question
-
Indexes (Clustered vs Non-Clustered)
-
View vs Table
- Table → physical storage of data.
- View → virtual table based on query.
CREATE VIEW HighSalary AS SELECT name, salary FROM Employees WHERE salary > 60000;
-
UNION vs UNION ALL
UNION
→ removes duplicates.UNION ALL
→ keeps duplicates. -
INNER JOIN vs LEFT JOIN
- INNER JOIN → returns only matching rows.
- LEFT JOIN → all rows from left + matched rows from right.
- RIGHT JOIN → all rows from right + matched rows from left.
- FULL JOIN → all rows from both sides.
-
WHERE vs HAVING
WHERE
→ filters rows before grouping.HAVING
→ filters groups after aggregation.
SELECT department, COUNT(*) FROM Employees WHERE salary > 50000 GROUP BY department HAVING COUNT(*) > 5;
-
Primary Key Foreign Key
Primary Key
- Uniquely identifies each row.
- A table can have only one primary key, but it may consist of multiple columns (composite key).
Foreign Key
- Ensures referential integrity by linking two tables.
CREATE TABLE Orders ( OrderID INT PRIMARY KEY, CustomerID INT, FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID) );
-
DELETE vs TRUNCATE vs DROP
-
DELETE
→ removes rows (can useWHERE
).TRUNCATE
→ removes all rows (faster, cannot useWHERE
).DROP
→ deletes the whole table structure.
DELETE FROM Employees WHERE id=5; -- removes one row TRUNCATE TABLE Employees; -- removes all rows DROP TABLE Employees; -- deletes table completely
-
-
types of SQL commands?
- DDL (Data Definition Language): CREATE, DROP, ALTER, TRUNCATE
- DML (Data Manipulation Language): INSERT, UPDATE, DELETE
- DQL (Data Query Language): SELECT
- DCL (Data Control Language): GRANT, REVOKE
- TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT
-
What is SQL?
SQL (Structured Query Language) is used to interact with relational databases (insert, update, delete, and query data).
SQL is a database computer language designed for the retrieval and management of data in a relational database. SQL stands for Structured Query Language. This tutorial will give you a quick start to SQL. It covers most of the topics required for a basic understanding of SQL and to get a feel of how it works.