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

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

SQL Interview Questions

The document provides a comprehensive overview of SQL, including definitions of SQL, databases, and various SQL commands such as DDL, DML, DCL, and TCL. It explains key concepts like primary and foreign keys, normalization, denormalization, and the purpose of constraints. Additionally, it covers SQL queries, operators, views, joins, and aggregate functions.

Uploaded by

waghmithu
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)
43 views3 pages

SQL Interview Questions

The document provides a comprehensive overview of SQL, including definitions of SQL, databases, and various SQL commands such as DDL, DML, DCL, and TCL. It explains key concepts like primary and foreign keys, normalization, denormalization, and the purpose of constraints. Additionally, it covers SQL queries, operators, views, joins, and aggregate functions.

Uploaded by

waghmithu
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 Interview Questions

1. What is SQL?

SQL (Structured Query Language) is a standard programming language used to


communicate with relational databases. It allows users to create, read, update, and
delete data, and provides commands to define database schema and manage
database security.

2. What is a database?

A database is an organized collection of data stored electronically, typically structured


in tables with rows and columns. It is managed by a database management
system (DBMS), which allows for efficient storage, retrieval, and manipulation of
data.

3. What are the main types of SQL commands?

SQL commands are broadly classified into:

• DDL (Data Definition Language): CREATE, ALTER, DROP, TRUNCATE.

• DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE.

• DCL (Data Control Language): GRANT, REVOKE.

• TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT.

4. What is the difference between CHAR and VARCHAR2 data types?

• CHAR: Fixed-length storage. If the defined length is not fully used, it is padded
with spaces.

• VARCHAR2: Variable-length storage. Only the actual data is stored, saving space
when the full length is not needed.

5. What is a primary key?

A primary key is a unique identifier for each record in a table. It ensures that no two rows
have the same value in the primary key column(s), and it does not allow NULL values.

6. What is a foreign key?

A foreign key is a column (or set of columns) in one table that refers to the primary key in
another table. It establishes and enforces a relationship between the two tables,
ensuring data integrity.

7. What is the purpose of the DEFAULT constraint?


The DEFAULT constraint assigns a default value to a column when no value is provided
during an INSERT operation. This helps maintain consistent data and simplifies data
entry.

8. What is normalization in databases?

Normalization is the process of organizing data in a database to reduce


redundancy and improve data integrity. This involves dividing large tables into smaller,
related tables and defining relationships between them to ensure consistency and
avoid anomalies.

9. What is denormalization, and when is it used?

Denormalization is the process of combining normalized tables into larger tables for
performance reasons. It is used when complex queries and joins slow down data
retrieval, and the performance benefits outweigh the drawbacks of redundancy.

10. What is a query in SQL?

A query is a SQL statement used to retrieve, update, or manipulate data in a database.


The most common type of query is a SELECT statement, which fetches data from one or
more tables based on specified conditions.

11. What are the different operators available in SQL?

• Arithmetic Operators: +, -, *, /, %

• Comparison Operators: =, !=, <>, >, <, >=, <=

• Logical Operators: AND, OR, NOT

• Set Operators: UNION, INTERSECT, EXCEPT

• Special Operators: BETWEEN, IN, LIKE, IS NULL

12. What is a view in SQL?

A view is a virtual table created by a SELECT query. It does not store data itself, but
presents data from one or more tables in a structured way. Views simplify complex
queries, improve readability, and enhance security by restricting access to specific rows
or columns.

13. What is the purpose of the UNIQUE constraint?

The UNIQUE constraint ensures that all values in a column (or combination of columns)
are distinct. This prevents duplicate values and helps maintain data integrity.

14. What are the different types of joins in SQL?

• INNER JOIN: Returns rows that have matching values in both tables.
• LEFT JOIN (LEFT OUTER JOIN): Returns all rows from the left table, and
matching rows from the right table.

• RIGHT JOIN (RIGHT OUTER JOIN): Returns all rows from the right table, and
matching rows from the left table.

• FULL JOIN (FULL OUTER JOIN): Returns all rows when there is a match in either
table.

• CROSS JOIN: Produces the Cartesian product of two tables.

15. What is the difference between INNER JOIN and OUTER JOIN?

• INNER JOIN: Returns only rows where there is a match in both tables.

• OUTER JOIN: Returns all rows from one table (LEFT, RIGHT, or FULL), and the
matching rows from the other table. If there is no match, NULL values are
returned for the non-matching side.

16. What is the purpose of the GROUP BY clause?

The GROUP BY clause is used to arrange identical data into groups. It is typically used
with aggregate functions (such as COUNT, SUM, AVG) to perform calculations on each
group rather than on the entire dataset.

17. What are aggregate functions in SQL?

Aggregate functions perform calculations on a set of values and return a single value.
Common aggregate functions include:

• COUNT(): Returns the number of rows.

• SUM(): Returns the total sum of values.

• AVG(): Returns the average of values.

• MIN(): Returns the smallest value.

• MAX(): Returns the largest value.

You might also like