mysql列操作:添加、删除、重命名、修改列属性

一、修改表名:

1:alter table `old_table` rename to `new_table`;

2:rename table `old_table` to `new_table`;

二、修改列的相关操作:

简单来说表创建完后一些更改表结构的操作都会是

alter table `table_name` operation[add,drop,change,modify,rename];

添加新列标准写法:alter table `table_name` add column `column_name` [other description];

添加新列简写法:alter table `table_name` add `column_name` [other description];

删除列标准写法:alter table `table_name` drop column `cloumn_name`;

删除列列简写法:alter table `table_name` drop `cloumn_name`;

重命名列名/修改列属性: 

alter table `table_name` change column `old_column` `new_column` [other description];

alter table `table_name` change  `old_column` `new_column` [other description];

修改列属性:

alter table `table_name` modify column `column_name` [other description];

alter table `table_name` modify `column_name` [other description];

change 和 modify都可以重新定义现有列的属性,change的功能更强大些,但必须有`old_column` `new_column`,即便你不想重命名你也得写上一样的,modify则是对现有的列属性进行修改。


转载于:https://my.oschina.net/sallency/blog/373330

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值