MySQL新增欄位和刪除字段

2021-08-20 18:00:05 字數 1042 閱讀 7471

直接在mysql或者mysql工具命令列連線並操作

mysql新增欄位和刪除字段

alter add命令用來增加表的字段。

alter add命令格式:alter table 表名 add欄位 型別 其他;

例如,在表myclass中新增了乙個欄位passtest,型別為int(4),預設值為0:

mysql> alter table myclass add passtest int(4) default '0';

1) 加索引

mysql> alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]);

例子: mysql> alter table employee add index emp_name (name);

2) 加主關鍵字的索引

mysql> alter table 表名 add primary key (欄位名);

例子: mysql> alter table employee add primary key(id);

3) 加唯一限制條件的索引

mysql> alter table 表名 add unique 索引名 (欄位名);

例子: mysql> alter table employee add unique emp_name2(cardnumber);

4) 刪除某個索引

mysql> alter table 表名 drop index 索引名;

例子: mysql>alter table employee drop index emp_name;

5) 增加字段

mysql> alter table table_name add field_name field_type;

6) 修改原欄位名稱及型別

mysql> alter table table_name change old_field_name new_field_name field_type;

7) 刪除字段

mysql alter table table_name drop field_name;

Mysql 新增字段 修改字段 刪除字段

alter table 表名 add 欄位名 字段型別 字段長度 default 預設值 comment 注釋 例如 alter table order add code char 6 default null comment 優惠碼 2 修改字段 修改欄位名 字段型別 長度 a 修改欄位名 alt...

Mysql 新增字段 修改字段 刪除字段

alter table 表名 add column 欄位名 字段型別 字段長度 default 預設值 comment 注釋 例如 alter table order add column code char 6 default null comment 優惠碼 2 修改字段 修改欄位名 字段型別 ...

ES 新增欄位和刪除字段

目錄es 刪除字段 put indexname indexname zq test age gender get zq test properties age event engine count gender name settings provided name zq test get zq t...