1. 程式人生 > 資料庫 >MySQL資料庫列的增刪改實現方法

MySQL資料庫列的增刪改實現方法

本文例項講述了MySQL資料庫列的增刪改實現方法。分享給大家供大家參考,具體如下:

新建表user_info:

CREATE TABLE user_info(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,username CHAR(20) NOT NULL DEFAULT '',gender TINYINT UNSIGNED NOT NULL DEFAULT 0,weight TINYINT UNSIGNED NOT NULL DEFAULT 0
)ENGINE=MyISAM DEFAULT CHARSET=utf8;

新增列預設在表的最後一列

語法:alter table 表名 add 列名 列型別 列屬性

alter table user_info add height tinyint unsigned not null default 0;

刪除列

語法:alter table 表名 drop 列名

alter table user_info drop height;

增加列,放在指定列之後

語法:alter table 表名 add 列名 型別 屬性 [預設值] after 指定列名

alter table user_info add height tinyint not null default 0 after username;

修改指定列名

語法:alter table 表名 change 舊列名 新列名 型別 屬性 預設值

alter table user_info change height shengao smallint not null default 0;

modify 修改列,但不能修改列名

語法:alter table 表名 modify 列名 型別 屬性 預設值

alter table user_info modify shengao tinyint not null default 0;

更多關於MySQL相關內容感興趣的讀者可檢視本站專題:《MySQL常用函式大彙總》、《MySQL日誌操作技巧大全》、《MySQL事務操作技巧彙總》、《MySQL儲存過程技巧大全》及《MySQL資料庫鎖相關技巧彙總》

希望本文所述對大家MySQL資料庫計有所幫助。