mysql的alter
2016-04-27 19:22
519 查看
1.alter操作表字段
(1)增加字段
alter table 表名 add 字段名 字段类型;
alter table student add name varchar(10);
(2)修改字段
alter table 表名 change 旧字段名 新字段名 字段类型;
alter table student change name name varchar(20)not null default 'liming';//修改字段类型
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(字段名)
(1)增加字段
alter table 表名 add 字段名 字段类型;
alter table student add name varchar(10);
(2)修改字段
alter table 表名 change 旧字段名 新字段名 字段类型;
alter table student change name name varchar(20)not null default 'liming';//修改字段类型
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(字段名)
相关文章推荐
- MySQL中的integer 数据类型
- MySQL存储过程
- mysql中int、bigint、smallint 和 tinyint的区别与长度
- mysql load data 导出、导入 csv
- source命令执行SQL脚本文件
- MySQL创建用户及权限控制
- MySQL管理数据表
- linux下mysql添加用户
- mysql procedure
- mysql触发器
- MySQL 备份和恢复策略
- mac下安装mysql(转载)
- mysql 修改编码 Linux/Mac/Unix/通用(杜绝修改后无法启动的情况!)
- MySQL数据的导出、导入(mysql内部命令:mysqldump、mysql)
- mysql数据行转列
- Linux下修改MySQL编码的方法
- MySQL Server 日志
- MySQL 安全事宜
- MySQL 备份与恢复