KEMBAR78
Complete SQL Interview Questions Guide | PDF | Database Index | Databases
0% found this document useful (0 votes)
10 views5 pages

Complete SQL Interview Questions Guide

Uploaded by

sujeetvishwa99
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)
10 views5 pages

Complete SQL Interview Questions Guide

Uploaded by

sujeetvishwa99
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/ 5

SQL Interview Questions for Freshers

Basic SQL Questions


Q: What is SQL?
A: Structured Query Language used to interact with databases.

Q: Difference between SQL and MySQL?


A: SQL = language, MySQL = RDBMS.

Q: What are DDL, DML, DCL, and TCL commands?


A: DDL → CREATE, ALTER, DROP DML → SELECT, INSERT, UPDATE, DELETE DCL →
GRANT, REVOKE TCL → COMMIT, ROLLBACK, SAVEPOINT

Q: Difference between DELETE, TRUNCATE, and DROP.


A: DELETE → removes rows (WHERE allowed, rollback possible) TRUNCATE → removes all rows
(faster, no WHERE) DROP → removes the entire table schema

Q: Difference between CHAR and VARCHAR?


A: CHAR → fixed length, VARCHAR → variable length

Query Writing Questions


Q: Fetch employees with salary > 50,000
A: SELECT * FROM Employees WHERE Salary > 50000;

Q: Find 2nd highest salary


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

Q: Count employees in each department


A: SELECT DeptID, COUNT(*) FROM Employees GROUP BY DeptID;

Q: Fetch duplicate records


A: SELECT Name, COUNT(*) FROM Employees GROUP BY Name HAVING COUNT(*) > 1;

Q: Employees without manager


A: SELECT * FROM Employees WHERE ManagerID IS NULL;

Joins & Relationships


Q: Types of Joins
A: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, CROSS JOIN

Q: Employee names with department names


A: SELECT E.Name, D.DeptName FROM Employees E INNER JOIN Departments D ON E.DeptID
= D.DeptID;

Q: Difference between WHERE and HAVING


A: WHERE → filters rows before grouping, HAVING → filters groups after GROUP BY

Q: What is a Self Join?


A: Joining a table with itself (like finding manager-employee relations).
Indexes & Keys
Q: Primary Key, Foreign Key, Unique Key
A: Primary Key → unique row, no NULL Foreign Key → links two tables Unique Key → ensures
unique values, allows NULL

Q: What is an Index?
A: Improves query performance by reducing search time.

Q: Clustered vs Non-Clustered Index


A: Clustered → sorts & stores rows (1 per table) Non-clustered → separate structure (many
allowed)

Advanced Concepts
Q: What is Normalization?
A: Organizing data to reduce redundancy (1NF, 2NF, 3NF, BCNF).

Q: What is Denormalization?
A: Opposite of normalization, improves query performance by adding redundancy.

Q: What is a View?
A: Virtual table created using a query.

Q: UNION vs UNION ALL


A: UNION → removes duplicates, UNION ALL → keeps duplicates

Q: Stored Procedure vs Function


A: Procedure → can return multiple values, supports DML Function → returns single value, used in
SELECT

Q: ACID Properties
A: Atomicity, Consistency, Isolation, Durability

Q: What are Transactions?


A: A unit of work that can be committed or rolled back.

Scenario-Based
Q: Nth Highest Salary
A: SELECT Salary FROM Employees E1 WHERE (N-1) = (SELECT COUNT(DISTINCT Salary)
FROM Employees E2 WHERE E2.Salary > E1.Salary);

Q: Employees joined in last 30 days


A: SELECT * FROM Employees WHERE JoinDate >= DATEADD(DAY, -30, GETDATE());

Q: Correlated vs Normal Subquery


A: Normal → independent query inside another query Correlated → inner query depends on outer
query
SQL Interview Questions for Freshers (40
Questions)
Q: What is Database?
A: A structured collection of data stored and managed electronically.

Q: What is DBMS?
A: Database Management System – software used to create and manage databases.

Q: What is RDBMS? How is it different from DBMS?


A: Relational DBMS stores data in tables with relationships. DBMS may or may not use tables.

Q: What is SQL?
A: Structured Query Language used for managing and querying databases.

Q: What is the difference between SQL and MySQL?


A: SQL is a query language. MySQL is a relational database system.

Q: What are Tables and Fields?


A: Table = collection of rows & columns. Field = column in a table.

Q: What are Constraints in SQL?


A: Rules applied to table columns (e.g., NOT NULL, UNIQUE, PRIMARY KEY).

Q: What is a Primary Key?


A: A unique identifier for each row in a table.

Q: What is a UNIQUE constraint?


A: Ensures all values in a column are unique.

Q: What is a Foreign Key?


A: A column that refers to the primary key of another table.

Q: What is a Join? List its different types.


A: Joins combine rows from multiple tables. Types: INNER, LEFT, RIGHT, FULL, CROSS.

Q: What is a Self-Join?
A: Joining a table with itself to compare rows within the same table.

Q: What is a Cross-Join?
A: Returns the Cartesian product of two tables.

Q: What is an Index? Explain its different types.


A: Index speeds up searches. Types: Clustered and Non-clustered.

Q: What is the difference between Clustered and Non-clustered index?


A: Clustered → sorts & stores data rows; only one allowed. Non-clustered → separate index
structure; many allowed.

Q: What is Data Integrity?


A: Ensuring accuracy and consistency of data in a database.

Q: What is a Query?
A: A request to retrieve or manipulate data in a database.

Q: What is a Subquery? What are its types?


A: A query inside another query. Types: Correlated and Non-correlated.

Q: What is the SELECT statement?


A: Used to fetch data from one or more tables.
Q: What are some common clauses used with SELECT query in SQL?
A: WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.

Q: What are UNION, MINUS and INTERSECT commands?


A: UNION → combine results, removes duplicates. MINUS → difference. INTERSECT → common
rows.

Q: What is Cursor? How to use a Cursor?


A: Cursor is a pointer to fetch row-by-row results. Used in stored procedures.

Q: What are Entities and Relationships?


A: Entity = object (table). Relationship = association between entities.

Q: List the different types of relationships in SQL.


A: One-to-One, One-to-Many, Many-to-Many.

Q: What is an Alias in SQL?


A: Temporary name given to a table or column using AS.

Q: What is a View?
A: A virtual table based on the result of a query.

Q: What is Normalization?
A: Organizing data to reduce redundancy.

Q: What is Denormalization?
A: Adding redundancy to improve performance.

Q: What are the various forms of Normalization?


A: 1NF, 2NF, 3NF, BCNF, 4NF, 5NF.

Q: What are the TRUNCATE, DELETE and DROP statements?


A: DELETE → remove rows, TRUNCATE → remove all rows, DROP → remove table.

Q: What is the difference between DROP and TRUNCATE statements?


A: DROP deletes schema and data, TRUNCATE only deletes rows.

Q: What is the difference between DELETE and TRUNCATE statements?


A: DELETE → slower, supports WHERE & rollback. TRUNCATE → faster, no WHERE, minimal
logging.

Q: What are Aggregate and Scalar functions?


A: Aggregate → operate on set (SUM, AVG). Scalar → operate on single value (LEN, UPPER).

Q: What is User-defined function? What are its various types?


A: Custom function created by user. Types: Scalar, Inline, Multi-statement.

Q: What is OLTP?
A: Online Transaction Processing → handles day-to-day transactions.

Q: What are the differences between OLTP and OLAP?


A: OLTP = transactional, OLAP = analytical.

Q: What is Collation? What are the different types of Collation Sensitivity?


A: Collation defines how data is sorted/compared. Sensitivities: Case, Accent, Kana, Width.

Q: What is a Stored Procedure?


A: A precompiled set of SQL statements stored in the database.

Q: What is a Recursive Stored Procedure?


A: Procedure that calls itself until a condition is met.

Q: How to create empty tables with the same structure as another table?
A: CREATE TABLE new_table AS SELECT * FROM old_table WHERE 1=0;

You might also like