1. 创建表(Create Table):
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
...
);
2. 插入数据(Insert Into):
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
3. 查询数据(Select):
SELECT column1, column2, ...
FROM table_name
WHERE condition;
4. 更新数据(Update):
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
5. 删除数据(Delete):
DELETE FROM table_name
WHERE condition;
6. 条件筛选(Where):
SELECT column1, column2, ...
FROM table_name
WHERE condition;
7. 排序(Order By):
SELECT column1, column2, ...
FROM table_name
ORDER BY column1 [ASC | DESC], column2 [ASC | DESC], ...;
8. 聚合函数(Aggregate Functions):
SELECT COUNT(column), AVG(column), SUM(column), MAX(column), MIN(column)
FROM table_name
WHERE condition;
9. 连接表(Join):
SELECT columns
FROM table1
INNER JOIN table2 ON table1.column = table2.column;
10. 分组(Group By):
SELECT column1, COUNT(column2)
FROM table_name
GROUP BY column1;
11. 数据库事务(Transactions):
START TRANSACTION;
-- 执行一系列SQL语句
COMMIT; -- 提交事务
ROLLBACK; -- 回滚事务
这只是SQL语言的一小部分,实际上,SQL非常灵活,允许用户执行复杂的数据库操作。在使用SQL时,具体的语法可能会因数据库管理系统的不同而略有差异,因此需要根据具体的数据库系统查阅相应的文档。
转载请注明出处:http://www.pingtaimeng.com/article/detail/14014/SQL