3修改

1》 修改表名

   alter  table 旧表名 rename to 新表名;

   -- 示例: 把tb_temp1的名字修改成temp1
   -- alter table tb_temp1 rename to temp1;

2》 修改字段的数据类型

     alter table 表名 modify 字段名 新的数据类型 [约束];

    -- 示例: 把 tb_temp1表的c1字段的数据类型修改成text
    --  alter table tb_temp1 modify c1 text ;


3》 修改字段名

    alter table 表名 change 旧字段名  新字段名  数据类型;

    -- 示例:把tb_temp1表的c1 改成 cc1
    -- alter table tb_temp1 change c1 cc1 text;

4》 添加字段

    alter table 表名 add 新字段名  数据类型  约束
    [first|after 已经存在字段名];

    -- 示例:在tb_temp1表中添加int cc2
    alter table tb_temp1 add cc2 int;
  
5》 删除字段

    alter table 表名  drop 字段名;
   
6》 修改字段的排列位置
    alter table 表名 modify 字段名 数据类型 first | after 已经存在的列名;
   
    -- 让 cc3列在第一个显示
    alter table tb_temp1 modify cc3 varchar(30) first;

    alter table tb_temp1 modify cc3 varchar(30) after cc1;

    desc tb_temp1;  -- 查看表结构

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值