SQL Interview Questions
SQL Interview Questions
2. What is DBMS?
DBMS stands for Database Management System.
DBMS is a system software responsible for the creation, retrieval, updation, and
management of the database.
It ensures that our data is consistent, organized, and is easily accessible by
serving as an
interface between the database and its end-users or application software.
4. What is SQL?
SQL stands for Structured Query Language.
It is the standard language for relational database management systems.
It is especially useful in handling organized data comprised of entities
(variables) and relations between different entities of the data.
NOT NULL - Restricts NULL value from being inserted into a column.
CHECK - Verifies that all values in a field satisfy a condition.
DEFAULT - Automatically assigns a default value if no value has been specified for
the field.
UNIQUE - Ensures unique values to be inserted into the field.
INDEX - Indexes a field providing faster retrieval of records.
PRIMARY KEY - Uniquely identifies each record in a table.
FOREIGN KEY - Ensures referential integrity for a record in another table.
(INNER) JOIN:
Retrieves records that have matching values in both tables involved in the join.
This is the widely used join for queries.
There are different types of indexes that can be created for different purposes:
Unique Index:
Unique indexes are indexes that help maintain data integrity by ensuring
that no two rows of data in a table have identical key values.
Once a unique index has been defined for a table,
uniqueness is enforced whenever keys are added or changed within the index.
Non-Unique Index :
Non-unique indexes, on the other hand, are not used to enforce constraints
on the tables with which they are associated.
Instead, non-unique indexes are used solely to improve query performance
by maintaining a sorted order of data values that are used frequently.
Clustered index modifies the way records are stored in a database based on the
indexed column.
A non-clustered index creates a separate entity within the table which references
the original table.
Clustered index is used for easy and speedy retrieval of data from the database,
whereas, fetching records from the non-clustered index is relatively slower.
20. What are some common clauses used with SELECT query in SQL?
WHERE clause in SQL is used to filter records that are necessary, based on specific
conditions.
ORDER BY clause in SQL is used to sort the records based on some field(s) in
ascending (ASC) or descending order (DESC).
HAVING clause in SQL is used to filter records in combination with the GROUP BY
clause.
It is different from WHERE, since the WHERE clause cannot filter aggregated
records.
by the second SELECT query from the result-set obtained by the first SELECT query
and then return the filtered results from the first.
The INTERSECT clause in SQL combines the result-set fetched by the two SELECT
statements
where records from one match the other and then returns this intersection of
result-sets.
DELIMITER $$
CREATE PROCEDURE FetchAllStudents()
BEGIN
SELECT * FROM myDB.students;
END $$
DELIMITER ;