1、创建数据库:
CREATE DATABASE database_name;
2、删除数据库:
DROP DATABASE database_name;
3、选择数据库:
USE database_name;
4、创建表:
CREATE TABLE table_name (
column1 datatype [condition],
column2 datatype [condition],
...
);
5、删除表:
DROP TABLE table_name;
6、插入数据:
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
7、更新数据:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
8、删除数据:
DELETE FROM table_name WHERE condition;
9、查询数据:
SELECT column1, column2, ... FROM table_name WHERE condition;
10、查询数据(无条件):
SELECT * FROM table_name;
11、查询排序:
SELECT * FROM table_name ORDER BY column1 ASC|DESC;
12、查询去重:
SELECT DISTINCT column1 FROM table_name;
13、查询计数:
SELECT COUNT(*) FROM table_name;
14、查询条件:
SELECT * FROM table_name WHERE column1 = value1 AND column2 < value2;
15、模糊查询(通配符 %):
SELECT * FROM table_name WHERE column1 LIKE 'value%';
16、聚合函数(求和、平均值、最大值、最小值):
SELECT SUM(column1), AVG(column2), MAX(column3), MIN(column4) FROM table_name;
17、分组查询:
SELECT column1, COUNT(*) FROM table_name GROUP BY column1;
18、连接表查询(内连接、左连接、右连接、全连接):
SELECT * FROM table1 JOIN table2 ON table1.column = table2.column;
19、创建索引:
CREATE INDEX index_name ON table_name (column1, column2, ...);
20、删除索引:
DROP INDEX index_name ON table_name;