Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views3 pages

SQL Mock Interview Questions Tushar

The document contains SQL mock interview questions and answers covering fundamental concepts such as SQL vs MySQL, types of SQL statements, and differences between DELETE, TRUNCATE, and DROP. It also discusses SQL joins, execution order, window functions, common table expressions, and indexing. Additionally, it highlights the importance of primary and foreign keys, constraints, and provides examples of index creation.

Uploaded by

171Tanmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

SQL Mock Interview Questions Tushar

The document contains SQL mock interview questions and answers covering fundamental concepts such as SQL vs MySQL, types of SQL statements, and differences between DELETE, TRUNCATE, and DROP. It also discusses SQL joins, execution order, window functions, common table expressions, and indexing. Additionally, it highlights the importance of primary and foreign keys, constraints, and provides examples of index creation.

Uploaded by

171Tanmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Mock Interview Questions & Answers

1. What is SQL? Difference between SQL and MySQL?

SQL (Structured Query Language) is used to manage and manipulate relational databases. MySQL is a database
management system that uses SQL.

2. Types of SQL Statements

DDL: CREATE, ALTER, DROP


DML: INSERT, UPDATE, DELETE
DCL: GRANT, REVOKE
TCL: COMMIT, ROLLBACK

3. WHERE vs HAVING

WHERE filters rows before grouping.


HAVING filters after GROUP BY.

4. DELETE vs TRUNCATE vs DROP

DELETE: Deletes rows (can rollback)


TRUNCATE: Deletes all rows (no rollback)
DROP: Deletes table structure

5. Primary vs Foreign Key

Primary: Uniquely identifies a row.


Foreign: Links to primary key in another table.

6. Constraints in SQL

NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEFAULT

7. Joins in SQL

INNER JOIN: Common rows


LEFT JOIN: All from left + matched right
RIGHT JOIN: All from right + matched left
FULL JOIN: All rows
CROSS JOIN: Cartesian product
SELF JOIN: Table joined with itself

8. GROUP BY Usage
SQL Mock Interview Questions & Answers

Used to group rows and perform aggregate functions like SUM, COUNT, etc.

9. SQL Execution Order

1. FROM
2. JOIN
3. WHERE
4. GROUP BY
5. HAVING
6. SELECT
7. ORDER BY
8. LIMIT

10. Second Highest Salary

SELECT MAX(Salary) FROM Employees WHERE Salary < (SELECT MAX(Salary) FROM Employees);

11. Window Functions

RANK(), DENSE_RANK(), ROW_NUMBER(), LAG(), LEAD(), SUM() OVER(), etc.

12. CTE (Common Table Expression)

WITH temp AS (SELECT ...) SELECT * FROM temp;

13. Indexing in SQL

Index is a database object that improves query performance. Types:


- Clustered Index
- Non-Clustered Index
- Unique Index
- Composite Index

Use indexes on WHERE, JOIN, ORDER BY columns. Avoid indexing frequently updated or low-cardinality columns.

14. Clustered vs Non-Clustered Index

Clustered: Sorts table rows, one per table


Non-Clustered: Separate structure, many allowed

15. Index Creation Example


SQL Mock Interview Questions & Answers

CREATE INDEX idx_name ON Employees(Name);


CREATE CLUSTERED INDEX idx_salary ON Employees(Salary);

You might also like