SQL has a set of rules and instructions called Syntax.This article will list you for basic SQL syntax.

One thing to keep in mind is that SQL is case insensitive, meaning INSERT and insert are the same, but usually we make it obvious.Other slightly different in MySQL, the table name distinguishes between flowers and often.So, if you are working with MySQL, you must provide the correct table name as the name (in uppercase or lower case) in the database.

Overview of SQL

Overview of SQL

You can writeSQL statementson the same line or extend across multiple lines also.

Almost every operation on the database is done through commands in SQL.Here is a list of syntax commands in SQL.Specifically what these commands do, how to use them we will learn more in the following article.

AllSQL statementsbegin with a single keyword, such as SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW, and all semicolons.Mark;Used to separate SQL statements when multiple commands are called at the same time.

SELECT statement in SQL

SELECT cot1, cot2, cot3,... cotN
FROM ten_bang;

The DISTINCT clause in SQL

SELECT DISTINCT cot1, cot2, cot3,....cotN
FROM   ten_bang;

WHERE clause in SQL

SELECT cot1, cot2, cot3,... cotN
FROM   ten_bang
WHERE  DIEU_KIEN;

AND / OR clauses in SQL

SELECT cot1, cot2, cot3,... cotN
FROM   ten_bang
WHERE  DIEU_KIEN_1 {AND|OR} DIEU_KIEN_2;

The IN clause in SQL

SELECT cot1, cot2, cot3,... cotN
FROM   ten_bang
WHERE  ten_cot IN (giatri_1, giatri_2,...giatri_N);

The BETWEEN clause in SQL

SELECT cot1, cot2, cot3,... cotN
FROM   ten_bang
WHERE  ten_cot BETWEEN giatri_1 AND giatri_2;

The LIKE clause in SQL

SELECT cot1, cot2, cot3,... cotN
FROM   ten_bang
WHERE  ten_cot LIKE { PATTERN };

The ORDER BY clause in SQL

SELECT cot1, cot2, cot3,... cotN
FROM   ten_bang
WHERE  DIEU_KIEN
ORDER BY ten_cot {ASC|DESC};

The GROUP BY clause in SQL

SELECT SUM(ten_cot)
FROM   ten_bang
WHERE  DIEU_KIEN
GROUP BY ten_cot;

The COUNT clause in SQL

SELECT COUNT(ten_cot)
FROM   ten_bang
WHERE  DIEU_KIEN;

The HAVING clause in SQL

SELECT SUM(ten_cot)
FROM   ten_bang
WHERE  DIEU_KIEN
GROUP BY ten_cot
HAVING (dieu kien la ham so hoc);

CREATE TABLE statement in SQL

CREATE TABLE ten_bang(
cot1 kieu_du_lieu,
cot2 kieu_du_lieu,
cot3 kieu_du_lieu,
.....
cotN kieu_du_lieu,
PRIMARY KEY(mot hoac nhieu cot)
);

DROP TABLE statement in SQL

DROP TABLE ten_bang;

CREATE INDEX statement in SQL

CREATE UNIQUE INDEX ten_chi_muc
ON ten_bang ( cot1, cot2,...cotN);

DROP INDEX command in SQL

ALTER TABLE ten_bang
DROP INDEX ten_chi_muc;

DESC command in SQL

DESC ten_bang;

The TRUNCATE TABLE statement in SQL

TRUNCATE TABLE ten_bang;

The ALTER TABLE statement in SQL

ALTER TABLE ten_bang {ADD|DROP|MODIFY} ten_cot {kieu_du_lieu};

The ALTER TABLE (Rename) command in SQL

ALTER TABLE ten_bang RENAME TO ten_bang_moi;

INSERT INTO statement in SQL

INSERT INTO ten_bang( cot1, cot2,....cotN)
VALUES ( giatri_1, giatri_2,....giatri_N);

UPDATE statement in SQL

UPDATE ten_bang
SET cot1 = giatri_1, cot2 = giatri_2,....cotN=giatri_N
[ WHERE  DIEU_KIEN ];

The DELETE statement in SQL

DELETE FROM ten_bang
WHERE  {DIEU_KIEN};

CREATE DATABASE command in SQL

CREATE DATABASE ten_database;

DROP DATABASE command in SQL

DROP DATABASE ten_database;

USE command in SQL

USE ten_database;

Commit in SQL

COMMIT;

The ROLLBACK command in SQL

ROLLBACK;

Here is the basic command syntax in SQL, in the next article we will learn about the type of data in SQL.

Previous article:Learn about the most popular RDBMS

Leave a Comment

Close