MySql表结构修改

1.增加列【add 列名】

(1)在表的最后追加一列:

语法:alter table 表名 add 列名 列类型 列参数 ;
例如:alter table test add name char(30)not null default ‘Tom’;

(2)在某列后面加一列

语法:alter table 表名 add 列名 列类型 列参数 after 某列;
例子:alter table test add age int(4)not null after name;

(3)把某一列加在最前面

语法:alter table 表名 add 列名 列类型 列参数 first;
例子:alter table test add ID int(11) not null first;

**

2.删除列【drop 列名】

语法:alter table 表名 drop 列名;
例子:alter table test drop name;

3.修改列 【modify 列名】

(1)修改列类型

语法:alter table 表名 modify 列名 新类型 新参数;
例子:alter table test modify ID tinyint not null;

(2)修改列名和列类型

语法:alter table 表名 change旧列名 新列名 新参数;
例子:alter table test change name username char(20) not null;

4.查询列

(1)查询所有列(其实就是表结构)

语法:desc 表名;
例子:desc test;

语法:show columns from 表名;
例子:show columns from test;

(2)查询创建表的语句

语法:show create table 表名;
例子:show create table test;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值