SQL
SQL
SQL Commands: It can be categorized into several types based on their functionality:
These commands are used to define, modify, and delete database objects such as tables, indexes,
and schemas.
TRUNCATE: Deletes all the rows in a table but doesn't remove the table itself.
These commands are used for manipulating the data stored in the database (inserting, updating,
and deleting records).
These commands are used to control access to data within the database.
These commands manage the changes made by DML commands. They are used to ensure data
integrity and control transaction behavior.
COMMIT;
ROLLBACK: Rolls back (undoes) the changes made in the current transaction.
ROLLBACK;
SAVEPOINT: Sets a point within a transaction to which you can later roll back.
SAVEPOINT savepoint1;
SET TRANSACTION: Used to set specific properties for the transaction, like isolation
level.
a. SELECT: This statement is used to query a database and retrieve data from one or more
tables.
Example:
b. WHERE: This clause is used to filter records that meet specific conditions.
d. ORDER BY: This clause is used to sort the result set in ascending or descending order.
Example:
2. Aggregate Functions
e. GROUP BY: This clause groups rows sharing a property (like values in a column) into
summary rows.
3. Join Operations
a. INNER JOIN: Returns rows when there is a match in both tables.
b. LEFT JOIN (LEFT OUTER JOIN): Returns all rows from the left table and matched rows
from the right table.
c. RIGHT JOIN (RIGHT OUTER JOIN): Returns all rows from the right table and matched
rows from the left table.
d. FULL JOIN (FULL OUTER JOIN): Returns rows when there is a match in either left or
right table.
e. CROSS JOIN: Returns the Cartesian product of two tables (all combinations).
4. Subqueries
a. Subquery in SELECT: You can use a subquery in the SELECT statement to return a value.
b. Subquery in WHERE: You can use subqueries in the WHERE clause to filter results.
c. Subquery in FROM
You can use a subquery in the FROM clause to treat the result as a table
b. PRIMARY KEY: A column or set of columns that uniquely identify each row in the table.
c. FOREIGN KEY
7. Transactions
a. BEGIN TRANSACTION
BEGIN TRANSACTION;
COMMIT;
ROLLBACK;