mysql alter修改数据库表结构用法
2011-05-22 18:13
585 查看
1.alter操作表字段
(1)增加字段
alter table 表名 add 字段名 字段类型;
alter table student add name varchar(10);
(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 student add name varchar(10);
(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 alter修改数据库表结构用法
- mysql alter修改数据库表结构用法
- MySQL alert修改数据库表结构用法
- 根据sql脚本修改数据库表结构的几种解决方案
- mysql alter 语句用法,添加、修改、删除字段等
- 修改SQL-SERVER数据库表结构的SQL命令
- mysql alter 语句用法,添加、修改、删除字段等
- 数据库修改表结构SQL
- 数据库表中列类型的修改和ALTER的用法
- MYSQL中修改表结构ALTER用法
- 批量修改数据库中某个字段里面的部分内容(mysql数据库replace的用法)
- android 升级数据库 修改表结构
- 如何查看什么时间有哪些数据库对象结构被修改过
- mysql alter 语句用法,添加、修改、删除字段、索引、主键等
- 修改SQL-SERVER数据库表结构的SQL命令
- 2.数据库文件和表结构的修改
- mysql alter 语句用法,添加、修改、删除字段等
- POSTGRESQL 创建表结构、修改字段、导入导出数据库(支持CSV)
- 数据库:在修改表结构的时候提示不允许保存更改的解决方法
- android 升级数据库 修改表结构