标签:
需要用到,整理了一下。(为了容易看,都改成小写)
查看表创建语句:show create table table_name;
改变表名:alter table old_table rename [to] new_table;//rename
修改表数据类型:alter table table_name modify column_name attributes//modify
修改字段名:alter table table_name change old_name new_name new_attributs;//change
增加字段:alter table table_name add new_name new_attributes;//add
e.g. alter table books add title char(20) NOT NULL primary key first;//first
//置于最前面
alter table new_name add author char(30) NOT NULL after name;//after
//置于name字段之后
删除字段:alter table table_name drop column_name;//drop
修改字段位置:alter table table_name modify file_name attr after column_name;
修改数据表引擎:alter table table_name engine=new_engine;//engine
查看数据表引擎:show table status from database_name where name=‘table_name‘;//status
//上述也查看了表的其他基本信息
删除表的外键约束:alter table table_name drop foreing key key_name;
添加索引:alter table table_name add index index_name(column name);
alter table table_name add unique(column list name);
alter table table_name add primary key(column list names);
//index_name可选,缺省为第一个column
create index index_name on table_name(column list names);
create unique index index_name on table_name(column list names);
//create无法创建primary key索引
删除索引:alter table table_name drop index index_name;
alter table table_name drop primary key;
drop index index_name on table_name;
查看索引:show index from talbe_name;
修改数据库编码:
数据库: ALTER DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
表:ALTER TABLE table_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql修改数据结构
标签:
原文地址:http://www.cnblogs.com/lingeros/p/5004957.html