TCL - Transaction Control Language
TCL - Transaction Control Language
Though many resources claim there to be one more categories of SQL clauses TCL
- Transaction Control Language that we will see in detail.
DDL or Data Definition Language actually consists of the SQL commands that can
be used to define the database schema(structure). It simply deals with
descriptions of the database schema and is used to create and modify the
structure of database objects in the database.
a.) CREATE - It is used to create the database or its objects (like table, index,
function, views, store procedure and triggers).
DQL statements are used for performing queries on the data within schema
objects. The purpose of the DQL Command is to get some schema relation based
on the query passed to it.
Note :- '*' means all, so the above statement is used to retrieves or give the whole
table.
The SQL commands that deals with the manipulation of data present in the
database belong to DML or Data Manipulation Language and this includes most of
the SQL statements.
2. If you are adding values for all the columns of the table, you do not need to
specify the column names in the SQL query. However, make sure the order of the
values is in the same order as the columns in the table.
Note: Be careful when updating records in a table! Notice the WHERE clause in
the UPDATE statement. The WHERE clause specifies which record(s) that should
be updated. If you omit the WHERE clause, all records in the table will be updated!
DCL includes commands such as GRANT and REVOKE which mainly deal with the
rights, permissions and other controls of the database system.
- Parameters Used:
user.
granted.
b.) REVOKE- withdraw user’s access privileges given by using the GRANT
command.
For Examples on Grant & revoke pls consider this :- Revoke & Grant by GFG
Transactions group a set of tasks into a single execution unit. Each transaction
begins with a specific task and ends when all the tasks in the group successfully
complete. If any of the tasks fail, the transaction fails. Therefore, a transaction has
only two results: success or failure.
A database transaction, by definition, must be atomic, consistent, isolated and
durable. These are popularly known as ACID properties.
• ACID properties
Any transaction must maintain the ACID properties, viz. Atomicity, Consistency,
Isolation, and Durability.
- Consistency − A transaction should take the database from one consistent state
to another consistent state. It should not adversely affect any data item in the
database.
• Transaction Operations
execution.
• What is a Schedule?
please consider this link for above topic :- Concurrency control by GURU99
2.) WHERE - It specifies which rows to retrieve.The WHERE clause works like an if
condition in any programming language. The WHERE clause is very useful when
you want to fetch the selected rows from a table.
• The GROUP BY statement is often used with aggregate functions to group the
result-set by one or more columns.
5.) ORDER BY - The ORDER BY keyword is used to sort the result-set in ascending
or descending order. The ORDER BY keyword sorts the records in ascending order
by default. To sort the records in descending order, use the DESC keyword.
7.) JOIN - A JOIN clause is used to combine rows from two or more tables, based
on a related column between them.
ON table1.column = table2.column;
Different Types of SQL JOINs :- Here are the different types of the JOINs in SQL:
• (INNER) JOIN: Returns records that have matching values in both tables
• LEFT (OUTER) JOIN: Returns all records from the left table, and the matched
records from the right table
• RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched
records from the left table
• FULL (OUTER) JOIN: Returns all records when there is a match in either left or
right table
Other Keywords :
1.) DISTINCT Keyword - Eliminate duplicate rows. If column contains NULL value,
distinct treats NULL as same value. Can be used with more than one column. Can
be used with • Select • Where • Group by • Aggregate functions • Limit clause .
2.) LIMIT Keyword - MySQL supports the LIMIT clause to select a limited number
of records
• SELECT 10 IN(15,10,25);
• SELECT column1,column2,...FROM table_name WHERE (expr|column_1) IN
('value1','value2',...);
• You can combine the IN operator with the NOT operator to determine if a value
does not match any value in a list or a subquery.
4.) BETWEEN Keyword - BETWEEN Condition will return the records where
expression is within the range of value1 and value2 (inclusive).
• You can use BETWEEN clause to replace a combination of "greater than equal
AND less than equal" conditions.
• You can combine the Between operator with the NOT operator to return all
rows where value does not lie in the given range.
5.) LIKE Keyword - The LIKE operator is used in a WHERE clause to search for a
specified pattern in a column. There are two wildcards used in conjunction with
the LIKE operator:
• % - The percent sign represents zero, one, or multiple characters
Let's say you wanted to search for a % or a _ character in the MySQL LIKE
condition. You can do this using an Escape character.
• SELECT * FROM table_name WHERE column_name LIKE 'G\%';
• We can override the default escape character in MySQL by providing the
ESCAPE modifier as follows:
• SELECT * FROM table_name WHERE column_name LIKE 'G!%' ESCAPE '!';
Other Commands :-
To Select Database –
• use database-name;
To Describe table –
• describe table-name;