SQL DML and DDL can divide SQL 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.
The most important DDL statement in SQL:
- 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
Example (Mysql):
We have a personnel database with such a data sheet:
Id |
LastName |
FirstName |
Address |
| City
1 |
Adams |
John |
Oxford Street |
London |
2 |
Bush |
George |
Fifth Avenue |
New York |
3 |
Carter |
Thomas |
Changan Street |
Beijing |
First create the database:
Create Database w3s;
To view the database that was created:
show databases;
Select the database you want to use:
Use DatabaseName;
Create a table:
CREATE TABLE TableName (------------------------------------------------)
To view the structure of a table:
DESC TableName;
To insert data into a table:
INSERT INTO tablename VALUES (--------) inserts all properties
INSERT INTO TableName (P1,P2,P3--) VALUES (n1, N2,N3--); order to correspond
Get the data from the table:
Select P1,p2,p3---PN from TableName;
Get all the data in the table by using the wildcard character *
Reference:
Http://www.w3school.com.cn/sql/sql_syntax.asp
Http://www.runoob.com/sql/sql-syntax.html
SQL Basic Syntax