mysql修改表结构添加删除修改字段
创建数据库
create database database_name
创建表
create table `user` ( `id` int(11) unsigned not null auto_increment comment 'id', primary key (`id`)) engine=myisam default charset=utf8;
删除表
drop table if exists `user`;
添加字段:
"alter table `user` add `id` int(11) not null default '0' comment 'id'"alter table `user` add `name` varchar( 20 ) character set utf8 collate utf8_general_ci null default null comment '姓名'
删除字段
alter table `user` drop column name
重命名
alter table table_name change old_field_name new_field_name field_type;
修改类型
alter table t1 change b b bigint not null; alter table infos change list list tinyint not null default '0';
加索引
alter table t1 rename t2;mysql> alter table tablename change depno depno int(5) not null; mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]); mysql> alter table tablename add index emp_name (name);加主关键字的索引 mysql> alter table tablename add primary key(id);加唯一限制条件的索引 mysql> alter table tablename add unique emp_name2(cardnumber);删除某个索引 mysql>alter table tablename drop index emp_name;修改表:
thinkphp3.2中添加字段,如:
m('admin')->execute("alter table `admin` add `id` int(11) not null default '0' comment 'id'");m('admin')->execute("alter table `admin` add `name` varchar(20) default null comment '姓名'");
推荐教程:《mysql》
以上就是mysql修改表结构及其添加删除修改字段功能的详细内容。