2018/11/3
It's recommended to read on Gitbook
A parse need to recognize and check the grammar. So, let's see the grammar of SQL.
There are four basic SQL grammar with fundamental operations:
SELECT
INSERT
UPDATE
DELETE
It's a CRUD (Create, Read, Update, Delete) schema, and it's very like HTTP requests -- POST
, GET
, PUT
, DELETE
.
Also, there are two syntax CREATE
and DELETE
, which are for creating and deleting databases, tables.
SQL is not a complicated language, so there are general forms for the 2 + 4
grammar.
CREATE DATABASE database_name
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
)
CREATE DATABASE testDB
CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);
SELECT column-names
FROM table-name
WHERE condition
ORDER BY sort-order
SELECT FirstName, LastName, City, Country
FROM Customer
WHERE City = 'Tokio'
ORDER BY LastName
INSERT table-name (column-names)
VALUES (column-values)
INSERT Supplier (Name, City, Country)
VALUES ('National Taiwan University', 'Taipei', 'Taiwan')
UPDATE table-name
SET column-name = column-value
WHERE condition
UPDATE OrderItem
SET Quantity = 22
WHERE Id = 38833
DELETE table-name
WHERE condition
DELETE User
WHERE Email = 'phy.tiger@gmail.com'
DROP DATABASE database_name
DROP TABLE table_name
DROP DATABASE testDB
DROP TABLE Shippers
Quick Link
1.StellarSQL Repository
2.Gitbook of this seriesAuthor
Liu, An-Chi (劉安齊). A software engineer, who loves writing code and promoting CS to people. Welcome to follow me at Facebook Page. More information on Personal Site and Github.