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