增删改查
1.增(create)
create table 表名 (
字段名 字段类型 约束 [comment '备注'],
字段名 字段类型 约束 [comment '备注'],
);
其中,
字段类型: int整型,varchar(大小)字符串…
数值类型:
字符串:
时间类:
约束:
约束 | 关键字 |
---|---|
非空约束 | not null |
唯一约束 | unique |
主键约束 | primary key 【auto_increment自动升序默认填写】 |
默认约束 | default |
外键约束 | foreign key |
2.删(drop)
drop table [if exists] 表名;
3.改(alter)
-- add
alter table 表名 add 字段名 字段类型 [约束] comment '描述信息';
-- drop column
alter table 表名 drop column 字段名 comment '描述信息';
-- modify/change(区别在于名字是否也修改)
alter table 表名 modify 字段名 新字段类型 comment '描述信息';
alter table 表名 change 字段名 新字段名 字段类型 [约束] comment '描述信息';
-- 修改表名
rename table 表名 to 新表名;
4.查(show/desc)
-- 查看当前数据库下的表
show tables;
-- 查看:数据库的建表语句
show create table 表名;
-- 查看指定表结构
desc 表名;