Các câu lệnh SQL

Câu Lệnh Cú Pháp
SELECT SELECT column1, column2, ... FROM table_name;
hoặc
SELECT * FROM table_name;
SELECT DISTINCT SELECT DISTINCT column1, column2, ... FROM table_name;
INSERT INTO INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
hoặc
INSERT INTO table_name VALUES (value1, value2, value3, ...);
UPDATE UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
DELETE DELETE FROM table_name WHERE condition;
hoặc
DELETE FROM table_name;
GROUP BY SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s);
SELECT INTO SELECT * INTO newtable [IN externaldb] FROM oldtable WHERE condition;
hoặc
SELECT column1, column2, column3, ... INTO newtable [IN externaldb] FROM oldtable WHERE condition;
INSERT INTO SELECT INSERT INTO table2 SELECT * FROM table1 WHERE condition;
hoặc
INSERT INTO table2 (column1, column2, column3, ...) SELECT column1, column2, column3, ... FROM table1 WHERE condition;
CASE CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
CREATE DATABASE CREATE DATABASE databasename;
DROP DATABASE DROP DATABASE databasename;
BACKUP DATABASE BACKUP DATABASE databasename TO DISK = 'filepath';
hoặc
BACKUP DATABASE databasename TO DISK = 'filepath' WITH DIFFERENTIAL;
CREATE TABLE CREATE TABLE table_name (column1 datatype,column2 datatype,column3 datatype,....);
hoặc
CREATE TABLE new_table_name AS SELECT column1, column2,... FROM existing_table_name WHERE ....;
DROP TABLE DROP TABLE table_name;
hoặc
TRUNCATE TABLE table_name;
ALTER TABLE ALTER TABLE table_name ADD column_name datatype;
hoặc
ALTER TABLE table_name DROP COLUMN column_name;
hoặc
ALTER TABLE table_name ALTER COLUMN column_name datatype;
CREATE INDEX CREATE INDEX index_name ON table_name (column1, column2, ...);
hoặc
CREATE UNIQUE INDEX index_name ON table_name (column1, column2, ...);
CREATE VIEW CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
hoặc
CREATE OR REPLACE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
DROP VIEW DROP VIEW view_name;