mysql修改表的语法

最近修改一个joomla网站,加了个留言本插件之后发现发的中文字符会乱码,于是我想到了会不会是数据库编码问题,果然该表的编码是latin1,于是我想到了改编码,顺便整理了一下如何改表结构的语法。

1.增加列
    1.1在表的最后面增加列
            alert table 表名 add 列名 列类型 列参数 ;
            如:alert table test add name char(30) not null default ’ ‘;
    1.2在某列的后面增加一列
            alert table 表名 add 列名 列类型 列参数
after 某列;
            如:alert table test add name varchar(20) after id;
1.3在最前边添加列
            alter table 表名 add 列名 列类型 列参数 first;
            如:alter table test add firstid int not null default 0 first;

2.修改列
    2.1修改列类型
            alter table 表名 modify 列名 新类型 新参数;
            如:alert table test modify username varchar(50) not null default ‘lili’;
    2.2修改列名和列类型
            alter table 表名 change 旧列名 新列名 新类型 新参数;
            如:alert table test change id userid int not null;

3.删除列
            alert table 表名 drop 列名;
            如:alert table test drop username;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kitt15

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值