您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySQL修改表结构操作命令总结

2025/1/9 13:09:09发布17次查看
表的结构如下: mysql show create table person; | person | create table `person` ( `number` int(11) default null, `name` varchar(255) default null, `birthday` date default null ) engine=myisam default charset=utf8 | 删除列: alter table perso
表的结构如下:
mysql> show create table person;
| person | create table `person` (
  `number` int(11) default null,
  `name` varchar(255) default null,
  `birthday` date default null
) engine=myisam default charset=utf8 |
删除列:
alter table person drop column birthday;
添加列:
alter table person add column birthday datetime;
修改列,把number修改为bigint:
alter table person modify number bigint not null;
或者是把number修改为id,类型为bigint:
alter table person change number id bigint;
添加主键:
alter table person add primary key (id);
删除主键:
alter table person drop primary key;
添加唯一索引:
alter table person add unique name_unique_index (`name`);
为name这一列创建了唯一索引,索引的名字是name_unique_index.
添加普通索引:
alter table person add index birthday_index (`birthday`);
删除索引:
alter table person drop index birthday_index;
alter table person drop index name_unique_index;
禁用非唯一索引
alter table person disable keys;
alter table...disable keys让mysql停止更新myisam表中的非唯一索引。激活非唯一索引
alter table person enable keys;
alter table ... enable keys重新创建丢失的索引。把表默认的字符集和所有字符列(char, varchar, text)改为新的字符集:
alter table person convert to character set utf8;
修改表某一列的编码
alter table person change name name varchar(255) character set utf8;
仅仅改变一个表的默认字符集
alter table person default character set utf8;
修改表名
rename table person to person_other;
移动表到其他数据库
rename table current_db.tbl_name to other_db.tbl_name;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product