mysql修改表结果

在这里插入图片描述

有这样一个表, 如上图所示。

查看系列命令
描述表结构
desc table_name
show full columns from table_name
查看索引
show index from table_name
查看建表语句
show create table table_name

添加字段
alter table test add column my_name int(11) after email;
删除字段
alter table test drop column my;

修改字段类型
alter table test modify my_name varchar(10);

修改字段名
alter table test change my_name new_name int(11);
修改字段默认值
通过change确实是可以的
alter table test change my my int(11) default 1;

修改表结构上面的索引

change和modify之间的区别
CHANGE:

Can rename a column and change its definition, or both.

Has more capability than MODIFY or RENAME COLUMN, but at the expense of convenience for some operations. CHANGE requires naming the column twice if not renaming it, and requires respecifying the column definition if only renaming it.

With FIRST or AFTER, can reorder columns.

MODIFY:

Can change a column definition but not its name.

More convenient than CHANGE to change a column definition without renaming it.

With FIRST or AFTER, can reorder columns.
posted @ 2022-03-06 10:39  叶常落  阅读(61)  评论(0编辑  收藏  举报