MySql知識總結

  1. mysql表增加字段和刪除字段
    1)增加或刪除單個字段:
    (1)增加一個字段
    格式:

    alter table table_name  add [column] col_name 列定義  [first|after 列名];
    

    例如:

    alter table test_table add name varchar(32) default null comment '姓名' after id;
    

    (2)刪除一個字段
    格式:

    alter table table_name drop [column] col_name;
    

    例如:

    alter table test_table drop name varchar(32);
    

    2)增加或刪除多個字段:
    (1)增加多個字段
    格式:

    alter table table_name add [column] col_name 列定義 [first|after 列名], 
                           add [column] col_name 列定義 [first|after 列名], 
                           add [column] col_name 列定義 [first|after 列名];
    

    例如:

    alter table test_table add name varchar(32) default null comment '姓名' after id,
                           add age  int         default null comment '年齡' after id,
                           add sex  varchar(5)  default null comment '性別' after id;
    

    (2)刪除多個字段
    格式:

    alter table table_name drop [column] col_name1,
                           drop [column] col_name2,
                           drop [column] col_name3;
    

    例如:

    alter table test_table drop name,
                           drop age ,
                           drop sex ;
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章