SQL (Structured Query Language) is a standard programming language used to manage and manipulate relational databases.
The main types of SQL commands are:
SELECT
, INSERT
, UPDATE
, DELETE
CREATE
, ALTER
, DROP
GRANT
, REVOKE
COMMIT
, ROLLBACK
, SAVEPOINT
INNER JOIN
returns records that have matching values in both tables.LEFT JOIN
returns all records from the left table and the matched records from the right table. If no match, NULL is returned for right table columns.Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. It involves dividing large tables into smaller tables and using relationships between them.
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
CROSS JOIN
SELF JOIN
A primary key is a column or a set of columns in a table that uniquely identifies each row in that table. It must contain unique values and cannot contain NULLs.
A foreign key is a column that creates a relationship between two tables. It points to the primary key in another table, ensuring referential integrity.
DELETE
removes rows from a table based on a condition, can be rolled back.TRUNCATE
removes all rows from a table without logging individual row deletions, cannot be rolled back.An index is a database object that improves the speed of data retrieval operations on a table at the cost of additional space and slower insertions, deletions, and updates.
WHERE
is used to filter rows before aggregation.HAVING
is used to filter rows after aggregation.Answer: A subquery is a query within another query, typically within the WHERE
, FROM
, or SELECT
clause, used to return results that are then used by the outer query.
Aggregate functions perform a calculation on a set of values to return a single value. Common aggregate functions include:
COUNT()
SUM()
AVG()
MIN()
MAX()
A view is a virtual table based on the result set of a SQL query. It does not store data but provides a way to look at data from one or more tables.
UNION
combines the results of two queries, removing duplicates.UNION ALL
combines the results without removing duplicates.A transaction is a sequence of SQL statements that are executed as a single unit of work. It ensures that all changes to the database are committed or rolled back together.
A stored procedure is a precompiled collection of one or more SQL statements that can be executed on demand, typically to perform a specific task.
CHAR
is a fixed-length string data type.VARCHAR
is a variable-length string data type.A trigger is a set of SQL statements automatically executed in response to certain events (e.g., INSERT
, UPDATE
, DELETE
) on a table.
The GROUP BY
clause is used to group rows that have the same values in specified columns into summary rows, like calculating aggregate values.
The DISTINCT
keyword is used to remove duplicate values from the result set.
A composite key is a primary key that consists of two or more columns in a table, where the combination of values uniquely identifies a row.
A self join is a type of join where a table is joined with itself.
The LIKE
operator is used to search for a specified pattern in a column.
An alias is a temporary name assigned to a table or column for the purpose of making the query more readable or concise.
A non-clustered index is an index that stores a separate structure from the data, and it points to the location of data instead of storing the data itself.
The RANK()
function assigns a rank to each row within a partition of a result set, with gaps between ranks for duplicate values.
Transaction isolation level determines the visibility of uncommitted changes made by one transaction to other transactions. Levels include:
READ UNCOMMITTED
READ COMMITTED
REPEATABLE READ
SERIALIZABLE
A correlated subquery is a subquery that references columns from the outer query, making it dependent on the outer query for execution.
The CASE
statement is used to create conditional logic in SQL queries, allowing you to return different values based on specified conditions.
EXPLAIN
is a command used to show the execution plan of a query, which helps analyze and optimize the performance of the query.