》创建一个普通的表
create table 表名称(
字段 类型 约束1 约束n,
字段 类型 约束1 约束n
)
》创建一个表,同时指定它的编码
create table 表名称(
字段 类型 约束1 约束n,
字段 类型 约束1 约束n
) character set 编码
show create table 表名称;
desc 表名称
primary key,非空且唯一
unique,维一
not null,不允许为空
auto_increment,自动增长
foreign key,外键
对字段类型的补充描述
unsigned,无符号,对于数字类型,无符号要直接放在类型后面,放错地方要报错
default,默认值
enum,枚举
更多添加中。。。
为表格添加字段》普通添加
alter table 表名称 add 字段 类型 约束;
》添加新字段在最头前
first
alter table 表名称 add 字段 类型 约束 first;
》添加新字段,在某一个字段的后面
after 字段
alter table 表名称 add 字段 类型 约束 after 字段;
》添加多个字段
alter table testtable1
add 字段1 类型 约束,
add 字段n 类型 约束;
alter table 表名称 drop 字段名
alter table 表名称 modify 字段 类型 约束;
alter table 表名称 change 旧字段名 新字段名 类型 约束;
rename table 旧表名 to 新表名;
alter table 表名称 character set 编码;