MySQL中的语法格式
时间: 2024-06-03 18:06:49 浏览: 63
mysql语法文档
MySQL语法格式如下:
1. 创建数据库
CREATE DATABASE dbname;
2. 使用数据库
USE dbname;
3. 创建表
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
4. 插入数据
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
5. 更新数据
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
6. 删除数据
DELETE FROM table_name WHERE condition;
7. 查询数据
SELECT column1, column2, ... FROM table_name WHERE condition;
8. 连接查询
SELECT column1, column2, ... FROM table1 INNER JOIN table2 ON condition;
9. 分组查询
SELECT column1, column2, ... FROM table_name GROUP BY column1;
10. 排序查询
SELECT column1, column2, ... FROM table_name ORDER BY column1 DESC;
11. 子查询
SELECT column1, column2, ... FROM table_name WHERE column1 IN (SELECT column1 FROM table2 WHERE condition);
12. 聚合函数
SELECT COUNT(column1), SUM(column2), AVG(column3) FROM table_name;
13. 视图
CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
14. 存储过程
CREATE PROCEDURE proc_name (parameters)
BEGIN
-- procedure body
END;
15. 触发器
CREATE TRIGGER trigger_name BEFORE INSERT ON table_name FOR EACH ROW
BEGIN
-- trigger body
END;
阅读全文