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

SQL Interview Questions & Answers Guide

The document provides an overview of SQL, including its definition, types of commands, and key concepts such as primary keys, foreign keys, joins, normalization, indexing, stored procedures, triggers, and views. It also explains differences between various SQL functions and commands, such as DELETE vs TRUNCATE, UNION vs UNION ALL, and RANK() vs DENSE_RANK(). Additionally, it covers ACID properties and the use of GROUP BY clause.

Uploaded by

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

SQL Interview Questions & Answers Guide

The document provides an overview of SQL, including its definition, types of commands, and key concepts such as primary keys, foreign keys, joins, normalization, indexing, stored procedures, triggers, and views. It also explains differences between various SQL functions and commands, such as DELETE vs TRUNCATE, UNION vs UNION ALL, and RANK() vs DENSE_RANK(). Additionally, it covers ACID properties and the use of GROUP BY clause.

Uploaded by

rutujakalaskar15
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

🔥 SQL Interview Questions & Answers 📊

What is SQL?
SQL (Structured Query Language) is a language used to communicate with databases. It
helps in storing, retrieving, updating, and deleting data efficiently.

What are the different types of SQL commands?


SQL commands are divided into five categories:
- **DDL (Data Definition Language)** – CREATE, ALTER, DROP
- **DML (Data Manipulation Language)** – INSERT, UPDATE, DELETE
- **DQL (Data Query Language)** – SELECT
- **TCL (Transaction Control Language)** – COMMIT, ROLLBACK
- **DCL (Data Control Language)** – GRANT, REVOKE

What is the difference between DELETE and TRUNCATE?


DELETE removes **specific rows** and can be rolled back.
TRUNCATE removes **all rows** and cannot be rolled back.

What is the primary key?


A **primary key** is a unique identifier for a row in a table. It **does not allow NULL
values**.

What is the foreign key?


A foreign keyis a column that creates a relationship between two tables by referring to the
**primary key** of another table.

What is the difference between WHERE and HAVING?


WHERE filters records **before aggregation**.
HAVING filters records **after aggregation**.

What are joins in SQL?


Joins are used to retrieve data from multiple tables. Types of joins:
- **INNER JOIN** – Returns matching records from both tables.
- **LEFT JOIN** – Returns all records from the left table and matching records from the
right.
- **RIGHT JOIN** – Returns all records from the right table and matching records from the
left.
- **FULL JOIN** – Returns all records from both tables.

What is normalization?
Normalization is the process of organizing data to **reduce redundancy** and improve
efficiency.
What are the different normal forms?
1. **1NF** – Removes duplicate columns.
2. **2NF** – Ensures all attributes are dependent on the primary key.
3. **3NF** – Removes transitive dependencies.
4. **BCNF** – A stronger version of 3NF.

What is indexing?
Indexing improves **query performance** by making data retrieval faster. Types of
indexes:
- **Clustered Index** – Sorts and stores rows in a table.
- **Non-Clustered Index** – Creates a separate structure for fast lookup.

What is a stored procedure?


A **stored procedure** is a set of SQL statements saved in the database that can be
executed repeatedly.

What is a trigger in SQL?


A **trigger** is a function that automatically executes in response to an event on a table.

What is the difference between UNION and UNION ALL?


UNION removes **duplicate** records.
UNION ALL includes **all** records, even duplicates.

What is a view in SQL?


A **view** is a virtual table created from a SQL query.

What is ACID in SQL?


ACID stands for:
- **Atomicity** – Transactions are all-or-nothing.
- **Consistency** – Data remains in a consistent state.
- **Isolation** – Transactions occur independently.
- **Durability** – Data remains even after a failure.

What is a subquery?
A **subquery** is a query inside another query. It is executed first, and its result is used by
the main query.

What is the difference between CHAR and VARCHAR?


CHAR(n) stores **fixed-length** strings.
VARCHAR(n) stores **variable-length** strings.

What is the difference between RANK() and DENSE_RANK()?


RANK() skips numbers if there are ties.
DENSE_RANK() does not skip numbers in case of ties.
What is the use of the GROUP BY clause?
GROUP BY is used with **aggregate functions** (SUM, COUNT, AVG, etc.) to group rows with
the same values.

What is the difference between NOW() and CURRENT_TIMESTAMP()?


Both return the **current date and time**, but CURRENT_TIMESTAMP() is SQL standard,
whereas NOW() is specific to MySQL.

Common questions

Powered by AI

Stored procedures are sets of SQL statements saved in the database that can be executed repeatedly, reducing redundancy and improving efficiency by encapsulating complex operations. They enhance security, as users can execute complex logic without direct access to data, and minimize network traffic, as procedures are executed within the database server .

Joins are used to retrieve related data from multiple tables. Types include INNER JOIN, which returns only matching records from both tables; LEFT JOIN, which returns all records from the left table and the matched records from the right table; RIGHT JOIN, which returns all records from the right table and matched records from the left table; and FULL JOIN, which returns all records when there is a match in either left or right table records .

DELETE is used to remove specific rows and can be rolled back, making it suitable for operations where selective record deletion and transaction safety are important. TRUNCATE removes all rows without the option to roll back, so it is ideal for quickly clearing a table when transaction support is not necessary .

Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. 1NF removes duplicate columns; 2NF ensures all attributes are dependent on the primary key; 3NF removes transitive dependencies, and BCNF is a stronger version of 3NF that further reduces redundancy by ensuring that every determinant is a candidate key .

A primary key is a unique identifier for a row in a table and does not allow NULL values, ensuring that each row is distinct. A foreign key, on the other hand, is a column that creates a relationship between two tables by referring to the primary key of another table. This enforces referential integrity and links related data across tables .

UNION removes duplicate records, making it useful when duplicate elimination is necessary for accurate data representation. UNION ALL includes all records, even duplicates, which is beneficial when duplicates carry relevant information or when performance is a priority since it is faster as no deduplication step is needed .

The ACID properties ensure reliable transaction processing by tackling crucial areas: Atomicity guarantees that transactions are all-or-nothing, preventing partial updates; Consistency ensures data remains in a valid state; Isolation allows transactions to operate independently, thus preventing concurrent transaction interferences; Durability ensures that once a transaction is committed, it will survive system failures, maintaining data integrity .

SQL commands are divided into five categories: DDL (Data Definition Language) includes operations like CREATE, ALTER, DROP to define database structures; DML (Data Manipulation Language) covers INSERT, UPDATE, DELETE to modify data; DQL (Data Query Language) uses SELECT to query data; TCL (Transaction Control Language) manages transactions with COMMIT, ROLLBACK; and DCL (Data Control Language) handles permissions with GRANT, REVOKE .

SQL (Structured Query Language) is a language used to communicate with databases. It helps in storing, retrieving, updating, and deleting data efficiently .

A view is a virtual table created from the result of a SQL query. It simplifies complex queries, improves security by restricting user access to a subset of data, and can encapsulate business logic. However, views can become complex to manage if overly nested and may not support direct manipulation of data, which could limit their flexibility .

You might also like