Basic Commands of SQL
Basic Commands of SQL
Employee
DCL
Data Control Language (DCL) statements. Some
examples:
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the
GRANT command
TCL
Transaction Control (TCL) statements are used to manage the
changes made by DML statements. It allows statements to be
grouped together into logical transactions.
COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can
later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like isolation
level and what rollback segment to use
ALTER
ALTER TABLE table_name ADD column_name
column-definition;
Output:
Name
-------------
Rahul Sharma
Anjali Bhagwat
Aliases for tables
SELECT s.first_name FROM student_details s;
In the above query, alias 's' is defined for the table
student_details and the column first_name is selected
from the table.
Aliases is more useful when
There are more than one tables involved in a query,
Functions are used in the query,
The column names are big or not readable,
Order By
The ORDER BY clause is used in a SELECT statement
to sort results either in ascending or descending order.
SELECT suppliers.supplier_id,
suppliers.supplier_name, orders.order_date FROM
suppliers INNER JOIN orders ON
suppliers.supplier_id = orders.supplier_id;
JOIN
LEFT JOIN
SELECT columns FROM table1 LEFT [OUTER] JOIN
table2 ON table1.column = table2.column;
SELECT suppliers.supplier_id,
suppliers.supplier_name, orders.order_date FROM
suppliers LEFT OUTER JOIN orders ON
suppliers.supplier_id = orders.supplier_id;
RIGHT JOIN
SELECT columns FROM table1 RIGHT [OUTER] JOIN
table2 ON table1.column = table2.column;
SELECT suppliers.supplier_id,
suppliers.supplier_name, orders.order_date FROM
suppliers FULL OUTER JOIN orders ON
suppliers.supplier_id = orders.supplier_id;
SQL INSERT INTO SELECT Statement
With SQL, you can copy information from one table
into another.
Since you can't list more than one table in the SQL
Server FROM clause when you are performing a delete,
you can use the SQL Server EXISTS clause.
DELETE WITH EXIST
DELETE FROM employees WHERE EXISTS ( SELECT
* FROM contacts WHERE contacts.contact_id =
employees.employee_id AND contacts.contact_id <
100 );
CEIL( number )
FLOOR( number )
ANY
SELECT column_name(s) FROM table_name WHERE
column_name ANY (value1,value2,...);