DML and DDL
SQL can be divided into two parts: Data manipulation Language (DML) and data definition language (DDL).
SQL (Structured Query language) is the syntax for executing queries. However, the SQL language also contains syntax for updating, inserting, and deleting records.
The query and update Directives form the DML portion of SQL:
- SELECT-Get data from a database table
- Update-updating data in a database table
- Delete-Deletes data from the database table
- INSERT into-inserts data into a database table
The Data definition language (DDL) portion of SQL gives us the ability to create or delete tables. We can also define indexes (keys), specify links between tables, and impose constraints between tables.
Create database-Creating new databases
ALTER DATABASE-Modify databases
CREATE table-Creates a new table
ALTER TABLE-Change (change) database table
drop table-Delete tables
Create index-Creating indexes (search key)
Drop INDEX-Delete indexes
SELECT from WHERE
- SELECT DISTINCT column name from table name. Distinct, removing duplicates
- and OR, link multiple judgments
- Order by sort, desc denotes reverse
- Insert into table name values (value 1, value 2,....) are inserted;
- Update table name SET column name = new value where column name = value, update
- Delete from table name WHERE column name = value, delete
Advanced Tutorials
Fetch the first n records:
SELECT *from Personslimit 5
column_name like pattern:% as a wildcard character
In operator : WHERE column_name in (value1,value2,...)
UNION
SELECT column_name (s) from Table_name1unionselect column_name (s) from table_name2
- AVG (column) returns the average of a column, SELECT avg (column_name) from table_name
- Count (column) returns the number of rows in a column (excluding NULL values), COUNT (DISTINCT column_name)
- COUNT (*) returns the number of rows selected
- First (column) returns the value of the number one record in the specified field, which can be combined with the order by
- Last (column) returns the value of the final record in the specified field, which can be combined with the order by
- Max (column) returns the highest value of a column
- MIN (column) returns the lowest value of a column
- SUM (column) returns the sum of a column
SQL GROUP by syntax
SELECT column_name, Aggregate_function (column_name) from Table_namewhere column_name operator Valuegroup by column_name
SQL having syntax
SELECT column_name, Aggregate_function (column_name) from Table_namewhere column_name operator Valuegroup by Column_ Namehaving aggregate_function (column_name) operator value
SQL Job Summary