- 创建数据库:
CREATE DATABASE database_name;
- 删除数据库:
DROP DATABASE database_name;
- 切换数据库:
USE database_name;
- 创建数据表:
CREATE TABLE table_name (
column1 datatype constraints,
column2 datatype constraints,
...
);
- 修改数据表:
ALTER TABLE table_name ADD column_name datatype constraints;
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE table_name MODIFY COLUMN column_name datatype constraints;
- 删除数据表:
DROP TABLE table_name;
- 插入数据:
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
- 更新数据:
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
- 删除数据:
DELETE FROM table_name WHERE condition;
- 查询数据:
SELECT column1, column2, ... FROM table_name WHERE condition ORDER BY column ASC/DESC LIMIT n OFFSET m;
其中,condition
是查询条件,ASC/DESC
表示升序/降序排列,n
是返回结果的数量,m
是结果集的偏移量。
- 创建索引:
CREATE INDEX index_name ON table_name (column1, column2, ...);
- 删除索引:
DROP INDEX index_name ON table_name;
- 创建视图:
CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
- 删除视图:
DROP VIEW view_name;
- 创建存储过程:
CREATE PROCEDURE procedure_name (IN parameter1 datatype, IN parameter2 datatype, ...) BEGIN ... END;
- 删除存储过程:
DROP PROCEDURE procedure_name;
- 调用存储过程:
CALL procedure_name(parameter1, parameter2, ...);