Gitbook: https://tigercosmos.github.io/lets-build-dbms/

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:

  • Read the data – SELECT
  • Insert new data – INSERT
  • Update existing data – UPDATE
  • Remove data – 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.

General Forms of SQL syntax

SQL is not a complicated language, so there are general forms for the 2 + 4 grammar.

CREATE

1
2
3
4
5
6
7
8
CREATE DATABASE database_name

CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
)
1
2
3
4
5
6
7
8
9
CREATE DATABASE testDB

CREATE TABLE Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

SELECT

1
2
3
4
SELECT column-names
FROM table-name
WHERE condition
ORDER BY sort-order
1
2
3
4
SELECT FirstName, LastName, City, Country
FROM Customer
WHERE City = 'Tokio'
ORDER BY LastName

INSERT

1
2
INSERT table-name (column-names)
VALUES (column-values)
1
2
INSERT Supplier (Name, City, Country)
VALUES ('National Taiwan University', 'Taipei', 'Taiwan')

UPDATE

1
2
3
UPDATE table-name
SET column-name = column-value
WHERE condition
1
2
3
UPDATE OrderItem
SET Quantity = 22
WHERE Id = 38833

DELETE

1
2
DELETE table-name
WHERE condition
1
2
DELETE User
WHERE Email = 'phy.tiger@gmail.com'

DROP

1
2
3
DROP DATABASE database_name

DROP TABLE table_name
1
2
3
DROP DATABASE testDB

DROP TABLE Shippers