Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

SQL Interview Questions

SQL (Structured Query Language) is used to manage and manipulate data in a relational database. SQL commands include DDL, DML, DCL and TCL. Primary keys uniquely identify rows, foreign keys link tables, and normalization reduces redundancy.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL Interview Questions

SQL (Structured Query Language) is used to manage and manipulate data in a relational database. SQL commands include DDL, DML, DCL and TCL. Primary keys uniquely identify rows, foreign keys link tables, and normalization reduces redundancy.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL Interview Questions

What is SQL?
SQL (Structured Query Language) is a programming language used to manage and manipulate
data stored in a relational database management system (RDBMS).

What are the different types of SQL commands?


SQL commands can be broadly categorized into four types: DDL (Data Definition Language), DML
(Data Manipulation Language), DCL (Data Control Language), and TCL (Transaction Control
Language).

What is a primary key in SQL?


A primary key is a column or set of columns in a table that uniquely identifies each row in that
table. It ensures that each row has a unique identifier and helps to enforce data integrity.

What is a foreign key in SQL?


A foreign key is a column or set of columns in one table that refers to the primary key in another
table. It establishes a relationship between the two tables, enabling data to be linked between
them.

What is normalization in SQL?


Normalization is the process of organizing data in a database to minimize redundancy and
dependency. It involves splitting large tables into smaller ones and creating relationships between
them to reduce data duplication.

What is a stored procedure in SQL?


A stored procedure is a precompiled set of SQL statements that can be called from an
application. It can take input parameters and return output and is often used to encapsulate
complex business logic.

What is a trigger in SQL?


A trigger is a special type of stored procedure that is automatically executed in response to
certain database events, such as an INSERT, UPDATE, or DELETE operation. It can be used to
enforce business rules, validate data, or audit changes.

What is a join in SQL?


A join is a SQL operation that combines rows from two or more tables based on a related column
between them. There are different types of joins, including INNER JOIN, LEFT JOIN, RIGHT JOIN, and
FULL OUTER JOIN.

What is a view in SQL?


A view is a virtual table created by a SQL query. It does not contain any data itself but is a saved
SQL query that can be used to retrieve data from one or more tables. Views can simplify complex
queries, provide a simplified view of data for users, and ensure data security by limiting access to
specific columns.

What is a subquery in SQL?


A subquery is a SQL query nested within another query. It is used to retrieve data that will be used
as part of a larger query. Subqueries can be used in various ways, such as to filter results,
compare values, or retrieve aggregate data.
SQL Interview Questions

What is indexing in SQL?


Indexing is the process of creating a data structure that improves the speed and efficiency of
data retrieval in a database. An index is created on one or more columns of a table, allowing the
database to quickly locate the rows that match a certain query condition.

What is a transaction in SQL?


A transaction is a sequence of SQL statements that are treated as a single unit of work.
Transactions ensure data consistency by either committing all changes to the database or rolling
back changes if an error occurs.

What is data integrity in SQL?


Data integrity refers to the accuracy and consistency of data in a database. SQL provides various
features to enforce data integrity, such as constraints, triggers, and referential integrity.

What is normalization in SQL?


Normalization is a process of organizing data in a database to eliminate data redundancy and
dependency. The goal of normalization is to create tables with well-defined relationships and
eliminate data anomalies.

What is a constraint in SQL?


A constraint is a rule or condition that is enforced on the data in a database. Constraints are used
to ensure data integrity and can be applied to tables, columns, or relationships between tables.
Common types of constraints include primary key, foreign key, unique, check, and not null
constraints.

What is the difference between UNION and UNION ALL in SQL?


UNION and UNION ALL are used to combine the results of two or more SELECT statements. The
main difference between them is that UNION removes duplicate rows, while UNION ALL does not.
Therefore, UNION ALL is generally faster than UNION, but may produce more rows.

What is the difference between WHERE and HAVING in SQL?


WHERE is used to filter rows based on a condition, while HAVING is used to filter groups based on
a condition. WHERE is used with SELECT, UPDATE, and DELETE statements, while HAVING is used
with SELECT statements that include a GROUP BY clause.

What is a stored function in SQL?


A stored function is a program that performs a specific task and returns a value. It can be called
from SQL statements and used to simplify complex queries or calculations. Stored functions can
take input parameters and can be created using SQL or other programming languages such as
PL/SQL.

What is the difference between a clustered index and a non-clustered index in SQL?
A clustered index determines the physical order of data in a table and is created on the primary
key or a unique column. A non-clustered index is created on a non-primary key column and does
not affect the physical order of data. While a table can have only one clustered index, it can have
multiple non-clustered indexes.
SQL Interview Questions

What is a cursor in SQL?


A cursor is a database object that allows you to retrieve and manipulate rows of data one at a
time. Cursors are often used in stored procedures and trigger to process data sequentially.

What is a temporary table in SQL?


A temporary table is a table that is created and exists only for the duration of a session or
transaction. It is used to store intermediate results and can be used in complex queries and
procedures.

What is a correlated subquery in SQL?


A correlated subquery is a subquery that depends on the outer query for its values. It is used to
filter results based on values from the outer query and can be more efficient than using multiple
joins.

What is a self-join in SQL?


A self-join is a joint operation that involves joining a table to itself. It is often used to find
relationships between rows within the same table.

What is the difference between a primary key and a foreign key in SQL?
A primary key is a column or set of columns that uniquely identifies each row in a table. A foreign
key is a column or set of columns that refer to the primary key of another table, establishing a
relationship between the two tables.

What is a deadlock in SQL?


A deadlock is a situation where two or more transactions are blocked, waiting for each other to
release resources. Deadlocks can occur when transactions acquire locks on resources in a
different order, leading to a circular dependency.

What is the difference between an inner join and an outer join in SQL?
An inner join returns only the rows that have matching values in both tables, while an outer join
returns all the rows from one table and the matching rows from the other table. There are three
types of outer join: left outer join, right outer join, and full outer join.

What is normalization in SQL?


Normalization is the process of organizing data in a database to reduce redundancy and improve
data integrity. It involves dividing a large table into smaller, more manageable tables and
establishing relationships between them.

What is denormalization in SQL?


Denormalization is the process of adding redundant data to a database to improve performance
or simplify queries. It involves duplicating data in one or more tables to avoid joining multiple
tables in a query.

What is a view in SQL?


A view is a virtual table that is based on the result of a SELECT statement. It is used to simplify
complex queries and to provide a layer of abstraction between the database and the user.
SQL Interview Questions

What is a subquery in SQL?


A subquery is a query that is nested inside another query. It is used to retrieve data from one or
more tables and to use that data as a condition for the outer query.

What is the difference between a view and a table in SQL?


A table is a physical object that stores data, while a view is a virtual object that represents a
SELECT statement. Views are used to simplify queries and to provide a layer of abstraction
between the database and the user.

What is the difference between a transaction and a query in SQL?


A transaction is a group of SQL statements that are executed together as a single unit of work. It
ensures that either all of the statements in the transaction are executed successfully, or none of
them are executed at all. A query is a single SQL statement that retrieves data from one or more
tables.

What is the difference between a database and a schema in SQL?


A database is a collection of related data that is stored on a computer. A schema is a logical
container for database objects, such as tables, views, and stored procedures. A database can
contain multiple schemas, and a schema can be used to organize and manage objects within a
database.

What is a trigger in SQL?


A trigger is a set of SQL statements that are automatically executed in response to certain events,
such as INSERT, UPDATE, or DELETE operations on a table. Triggers can be used to enforce
business rules, audit changes, and update related tables.

What is a stored procedure in SQL?


A stored procedure is a set of SQL statements that are stored in the database and can be
executed repeatedly. Stored procedures can accept input parameters and return output
parameters or result sets. They are used to simplify complex queries and to improve performance
by reducing network traffic.

What is a function in SQL?


A function is a set of SQL statements that are stored in the database and can be executed
repeatedly. Functions can accept input parameters and return a single value or a table. They are
used to perform calculations, manipulate data, and simplify complex queries.

What is a query plan in SQL?


A query plan is a set of steps that the database engine uses to execute a SQL statement. It
includes the order in which tables are accessed, the type of joins used, and the access methods
used to retrieve data from the tables. Query plans can be viewed and optimized to improve query
performance.

What is a clustered index in SQL?


A clustered index is an index that determines the physical order of data in a table. It is created on
the primary key of the table and is used to improve query performance by reducing the number of
disk I/O operations required to retrieve data.
SQL Interview Questions
What is a non-clustered index in SQL?
A non-clustered index is an index that is created on one or more columns of a table. It is used to
improve query performance by allowing the database engine to quickly find rows based on the
values in the indexed columns.

What is a deadlock in SQL?


A deadlock is a situation where two or more transactions are blocked, waiting for each other to
release resources. Deadlocks can occur when transactions acquire locks on resources in a
different order, leading to a circular dependency.

What is an index in SQL?


An index is a database object that is used to improve query performance by allowing the
database engine to quickly locate data in a table. It is created on one or more columns of a table
and can be either clustered or non-clustered.

What is a primary key in SQL?


A primary key is a column or set of columns that uniquely identifies each row in a table. It is used
to enforce data integrity and is typically used as the target of foreign key references in related
tables.

What is a foreign key in SQL?


A foreign key is a column or set of columns that refer to the primary key of another table. It is used
to establish a relationship between two tables and enforce referential integrity.

What is a self-join in SQL?


A self-join is a joint between a table and itself. It is used to retrieve data that relates to the same
table, such as hierarchical data or data with a recursive relationship.

What is a left join in SQL?


A left join is a type of join that returns all rows from the left table and matching rows from the
right table. If there are no matching rows in the right table, the result will contain NULL values for
the right table columns.

What is the right join in SQL?


A right join is a type of join that returns all rows from the right table and matching rows from the
left table. If there are no matching rows in the left table, the result will contain NULL values for the
left table columns.

What is a full outer join in SQL?


A full outer join is a type of join that returns all rows from both the left and right tables, including
any rows that do not have matching values in the other table. If there are no matching rows in
either table, the result will contain NULL values for the columns from the other table.

What is a union in SQL?


A union is an operation that combines the results of two or more SELECT statements into a single
result set. The SELECT statements must have the same number of columns and compatible data
types.

SoftwareTestingBRO

You might also like