最近修改一个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;