您当前的位置: 首页 >  sql

MySQL修改字段名、修改字段类型

发布时间:2021-03-02 14:18:58 ,浏览量:0

修改字段

类型、名、注释、类型长度、默认值

ALTER TABLE 表名 MODIFY [COLUMN] 字段名 新类型 新类型长度  新默认值  新注释; -- COLUMN关键字可以省略不写 -- 能修改字段类型、类型长度、默认值、注释  alter table table1 modify column column1 decimal(10,1) DEFAULT NULL COMMENT '注释'; -- 能修改字段类型、类型长度、默认值、注释  alter table table1 modify column1 decimal(10,2) DEFAULT NULL COMMENT '注释'; 
修改字段名
-- 字段名称未改变,修改字段类型、类型长度、默认值、注释 ALTER TABLE 表名 CHANGE [column] 旧字段名 新字段名 新数据类型; alter table table1 change column1 column1 varchar(100) DEFAULT 1.2 COMMENT '注释'; -- 修改字段名、字段类型、类型长度、默认值、注释 alter table table1 change column1 column2 decimal(10,1) DEFAULT NULL COMMENT '注释' -- 正常,能修改字段名、字段类型、类型长度、默认值、注释 alter table table1 change column2 column1 decimal(10,1) DEFAULT NULL COMMENT '注释' alter table table1 change column1 column2; -- 报错  mysql> alter table white_user change column name nick_name varchar(50) null comment '昵称'; -- 正确 Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 
更改表名 Table 从 db_a 要搬到 db_b
RENAME TABLE db_a.old_table TO db_b.new_table; 
MySQL Table 改名字(重命名)
RENAME TABLE old_table TO new_table; 
MySQL 两个 Table 互换名
RENAME TABLE old_table TO tmp_table, new_table TO old_table, tmp_table TO new_table; 
其实

最简单的,打开 IDEA 直接GUI修改!

关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    115984博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0536s