mysql alter修改数据库表结构用法

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;

转载于:https://www.cnblogs.com/jiaxiaoai/archive/2011/05/22/2053719.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值