• mysql alter用法场景


    mysql中alter主要有两种使用场景,第一种是修改表信息如表名等,第二种是修改表字段信息,如添加字段,修改字段等。第二种使用较多。

    第一种修改表信息场景如下:

    (1)修改表名

    alter table test_a rename to sys_app;
    

    (2)修改表注释

    alter table sys_application comment '系统信息表';
    

    第二种修改表字段场景如下:

    (1)修改字段类型和注释

    alter table sys_application  modify column app_name varchar(20) COMMENT '应用的名称';
    

    (2)修改字段类型

    alter table sys_application  modify column app_name text;
    

    (3)设置字段允许为空

    alter table sys_application  modify column description varchar(255) null COMMENT '应用描述';
    

    (4)增加一个字段,并设置数据类型,且不为空,添加注释

    alter table sys_application add `url` varchar(255) not null comment '应用访问地址';  
    

    (5)增加主键

    alter table t_app add aid int(5) not null,add primary key (aid);  
    

    (6)增加自增主键

    alter table t_app add aid int(5) not null auto_increment ,add primary key (aid); 
    

    (7)修改为自增主键

    alter table t_app  modify column aid int(5) auto_increment ;
    

    (8)修改字段名字(要重新指定该字段的类型)

    alter table t_app change name app_name varchar(20) not null;
    

    (9)删除字段

    alter table t_app drop aid; 
    

    (10)在某个字段后增加字段

    -- 在哪个字段后面添加
    alter table `t_app` add column gateway_id int  not null default 0 AFTER `aid`; 
    

    (11)调整字段顺序

     -- 注意gateway_id出现了2次
    alter table t_app  change gateway_id gateway_id int not null after aid ;
    

    参考博文:https://www.cnblogs.com/zsg88/p/7818684.html

  • 相关阅读:
    KLSudoku的数独题目生成方法和难度控制说明
    对XChain和ForcingChain的实现解说
    开源数独游戏软件KLSudoku发布第一个Release版本
    每个 Vim 用户都应该阅读的文章
    自己常用的几个gvim的vimrc设置
    KLSudoku数独游戏软件1.1预览版发布
    KLSudoku数独游戏软件1.1正式版发布
    字符串
    .NET面试大全
    IIS是如何处理ASP.NET请求的
  • 原文地址:https://www.cnblogs.com/jasonboren/p/13680193.html
Copyright © 2020-2023  润新知