mysql 修改数据表结构
2017-10-07 10:56
429 查看
1.alter操作表字段
(1)增加字段
alter table 表名 add 字段名 字段类型;
ALTER TABLE sys_app_user add qq_openid VARCHAR(255) COMMENT 'qq登录';
(2)修改字段
alter table 表名 change 旧字段名 新字段名 字段类型;
alter table 表名 modify 字段名 字段类型;//修改字段类型
alter table student change name name varchar(20)not null default 'liming';//修改字段类型 default后边是
字段默认的值
alter table student change name name1 varchar(20)not null default 'liming';//修改字段名
(3)删除字段
alter table 表名 drop 字段名;
alter table student drop name;
2.alter 索引操作
(1)增加索引
alter table 表名 add index 索引名 (字段名1,字段名2.....);
alter table student add index stu_name(name);
(2)删除索引
alter table 表名 drop index 索引名;
alter table student drop index stu_name;
(3)查看某个表的索引
show index from 表名;
(4)增加唯一限制条件的索引
alter table 表名 add unique 索引名(字段名);
3.主键操作
增加主键:
alter table 表名 add primary key(字段名);
删除主键:
alter table 表名 drop primary key;(主键不是自动增长情况下)
alter table 表名 modify 字段 字段类型, drop primary key;(主键是自动增长情况下)
alter table 123 modify id int,drop primary key;
(1)增加字段
alter table 表名 add 字段名 字段类型;
ALTER TABLE sys_app_user add qq_openid VARCHAR(255) COMMENT 'qq登录';
(2)修改字段
alter table 表名 change 旧字段名 新字段名 字段类型;
alter table 表名 modify 字段名 字段类型;//修改字段类型
alter table student change name name varchar(20)not null default 'liming';//修改字段类型 default后边是
字段默认的值
alter table student change name name1 varchar(20)not null default 'liming';//修改字段名
(3)删除字段
alter table 表名 drop 字段名;
alter table student drop name;
2.alter 索引操作
(1)增加索引
alter table 表名 add index 索引名 (字段名1,字段名2.....);
alter table student add index stu_name(name);
(2)删除索引
alter table 表名 drop index 索引名;
alter table student drop index stu_name;
(3)查看某个表的索引
show index from 表名;
(4)增加唯一限制条件的索引
alter table 表名 add unique 索引名(字段名);
3.主键操作
增加主键:
alter table 表名 add primary key(字段名);
删除主键:
alter table 表名 drop primary key;(主键不是自动增长情况下)
alter table 表名 modify 字段 字段类型, drop primary key;(主键是自动增长情况下)
alter table 123 modify id int,drop primary key;
相关文章推荐
- MySQL数据表的基本操作二:表结构查看、修改与表操作
- mysql在线修改表结构大数据表的风险与解决办法归纳(数据量大的时候,alter死锁表)
- Mysql学习3——查看表结构、修改和删除数据表
- Mysql-01-数据库和数据表结构的建立和修改
- Mysql学习3——查看表结构、修改和删除数据表
- Mysql学习—查看表结构、修改和删除数据表
- MySQL入门——修改数据表4:添加主键约束、显示表结构、添加唯一约束
- Mysql学习—查看表结构、修改和删除数据表
- Mysql 数据表结构的修改
- 【转】Mysql千万级数据表结构修改
- mysql在线修改表结构大数据表的风险与解决办法归纳
- mysql在线修改表结构大数据表的风险与解决办法归纳
- mysql在线修改表结构大数据表的风险与解决办法归纳
- mysql在线修改表结构大数据表的风险与解决办法归纳
- mysql千万级数据表结构修改
- MySQL入门——修改数据表4:添加主键约束、显示表结构、添加唯一约束、添加外键约束
- mysql在线修改表结构大数据表的风险与解决办法归纳
- MySQL数据表的基本操作二:表结构修改
- MySQL使用pt-online-change-schema工具在线修改1.6亿级数据表结构
- 基于Linux的MySQL操作实例(修改表结构,MySQL索引,MySQL数据引擎)