1 创建数据库:
CREATE DATABASE database_name;
2使用数据库:
USE database_name;
3 删除数据库:
DROP DATABASE database_name;
4 创建表:
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
...
);
5 修改表名:
ALTER TABLE table_name RENAME TO new_table_name;
6 添加列:
ALTER TABLE table_name ADD column_name datatype constraint;
7 修改列名:
ALTER TABLE table_name CHANGE column_name new_column_name datatype constraint;
8 修改列的数据类型:
ALTER TABLE table_name MODIFY column_name new_datatype constraint;
9 删除列:
ALTER TABLE table_name DROP column_name;
10 创建索引:
CREATE INDE X index_name ON table_name (column1, column2, ...);
11 删除索引:
DROP INDEX index_name ON table_name;
12 创建主键约束:
ALTER TABLE table_name ADD CONSTRAINT pk_constraint PRIMARY KEY (column1, column2, ...);
13 创建唯一约束:
ALTER TABLE table_name ADD CONSTRAINT unique_constraint UNIQUE (column1, column2, ...);
14 创建外键约束:
ALTER TABLE table_name ADD CONSTRAINT foreign_key_constraint FOREIGN KEY (column) REFERENCES parent_table (parent_column);
14 删除约束:
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
16 创建视图:
CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
17 删除视图:
DROP VIEW view_name;
18 创建触发器:
CREATE TRIGGER trigger_name BEFORE/AFTER INSERT/UPDATE/DELETE ON table_name FOR EACH ROW trigger_body;
19 删除触发器:
DROP TRIGGER trigger_name;