SQL
SQL
SQL Classification
Commands Description
DDL Data Definition Language
DML Data Manipulation Language
TCL Transaction Control Language
DCL Data Control Language
Data Definition Language (DDL) statements are used to define the structure of the data in the
database such as tables, procedures, functions, views, etc.
Statement Description
CREATE Create a new object(table, procedure, function, view etc.) in the database
ALTER Modify the structure of database table
DROP Delete database Objects
RENAME Rename database Objects (table, view, sequence, private synonym)
TRUNCATE Remove all records of a table
Data Manipulation Language (DML) statements are used to manage data within a database object. It
allows manipulation and querying the existing database schema objects.
Statement Description
SELECT Retrieve rows/columns from a table.
INSERT Insert new data to a table.
UPDATE Update existing records of table.
DELETE Delete existing records from table.
MERGE INSERT new rows or UPDATE existing rows in a table based on the specified
conditions.
LOCK Lock one or more tables in the specified mode. Based on lock applied table access
TABLE denied or only real only access given to another user.
Transaction Control Language (TCL) statements are used to finalize the changes in the data made by
executing the DML statements.
Statement Description
COMMIT Permanently save transaction changes to the database.
ROLLBACK Restore the database to its original state since the last COMMIT.
SAVEPOINT Create a SAVEPOINT to be later used by ROLLBACK Command to undo changes up to that
point.
SET Set the transaction properties such as READ WRITE or READ ONLY access.
TRANSACTION
CREATE DATABASE Statement
SHOW DATABASES;
DROP DATABASE Statement
To Create a table
CREATE TABLE table_name(
...
);
empNum varchar(10),
lastName varchar(50),
firstName varchar(50),
email varchar(255) ,
dob date,
deptNum integer,
salary integer);
VALUES(column1_value, column2_value...columnN_value);
insert into employee_details values (1002, 'Murray', 'Keith', 'km@gmail.com', '2001-8-18',2, 25000);
insert into employee_details values (1003, 'Branson', 'John', 'jb@gmail.com', '1989-9-13',3, 15000);
UPDATE table_name
column_name2 = new_value,
...
[WHERE Condition];
UPDATE employee_details
SET email = 'jking@test.com'
WHERE empNum = 1001;
Update Multiple Columns
SELECT Statement
DELETE Statement
Use the DELETE statement to delete records from the existing table in the current schema or tables
of the schema on which you have the DELETE privilege.
Tutorial:
https://www.w3schools.com/mysql/default.asp
https://www.youtube.com/watch?v=duEkh8ZsFGs
https://www.youtube.com/watch?v=cWNBchp_WCM&t=3596s