mysql中用命令行在表中指定位置添加字段:
有以下表结构:
CREATE TABLE `table_name` (
`id` int(11) NOT NULL auto_increment,
`user_name` varchar(50) NOT NULL,
`time` datetime NOT NULL,
`op_contents` varchar(255) NOT NULL,
`log_type` tinyint(2) NOT NULL,
PRIMARY KEY (`id`),
KEY `log_type` (`log_type`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk
要想在id和user_name之间添加一个字段user_id使用如下命令:
alter table table_name add column user_id int(11) not null comment'用户id' after id;
关键在于after关键词.
修改字段命令
ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;