mysql資料庫字段操作

2021-09-09 06:16:17 字數 2206 閱讀 3910

–建立測試表

create table test(

id int;

);–add支援多列,change/drop需要在每列前新增關鍵字,逗號隔開,'column』可有可無

–新增多列

alter table test add (c1 char(1),c2 char(1));

alter table test add column (c1 char(1),c2 char(1));

alter table test add c1 char(1),add c2 char(1);

新增欄位-單個

alter table people add column name varchar(100) default null comment 『姓名』

新增欄位-多個

alter table ip_domain_local add (

`audit_status` int(10) default null comment '審核狀態:0:未審核;1:違規;2:正常;3:已通知;4:已處理',

`audit_time` datetime default null comment '審核時間',

`audit_user` varchar(50) default null comment '審核人',

`inform_user` varchar(50) default null comment '通知人',

`dispose_user` varchar(50) default null comment '處理人'

)

–修改多列

alter table 表名 change 原欄位名 新欄位名 欄位的型別;

alter table test change c1 c3 char(1),change c2 c4 char(1); --正確

alter table test change column c1 c3 char(1),change column c2 c4 char(1); --正確

–name關鍵字作為欄位名,重新命名需要加反引號() alter table table_name changename` field_name varchar(50);

alter table test change (c1 c3 char(1),c2 c4 char(1)); --錯誤

–修改表的字段型別

alter table 表名 modify column 欄位名 字段型別定義;

–刪除多列

alter table test drop c1,drop c2; --正確

alter table test drop column c1,drop column c2; --正確

刪除欄位-單個

alter table uc_account_history drop column gesture;

刪除欄位-多個

alter table uc_account_history

drop column gesture,

drop column gesture_time,

drop column finger_print,

drop column finger_print_time,

drop column face_image_id,

drop column face_image_time,

drop column touch_type;

alter table test drop c1,c2; --錯誤

alter table test drop (c1,c2); --錯誤

–刪除表的資料

delete from 表名;

truncate table 表名;

–表的重新命名

alter table 原表名 rename 現表名;

–調整表的順序:

alter tableuser_movement_logchangegatewayidgatewayidint not null default 0 after regionid

修改表主鍵

alter table uc_account_bak drop primary key ,add primary key ( id );

關於mysql索引相關 :

資料庫字段操作

1.熟悉oracle sql server資料庫欄位的操作 1 新增乙個新的字段 2 刪除乙個字段 3 修改字段型別 1.在表中新增乙個新的字段 alter table 表名 add 欄位名稱 資料型別 2.修改表中的欄位名稱與字段型別 修改欄位名 alter table 表名 rename col...

mysql資料庫字段加密

linux version centos7.3 mysql vrsion mysql5.6.34 最近兩天,接到業務上乙個需求,需要對錶中的部分字段 比如手機號,email 進行加密,在檢視mysql的相關資料後,發現需要對資料庫中的部分字段加密,基本就只能從業務層面的角度來實現。大概提供了如下幾個...

MySQL資料庫字段加密

一 匯入表結構 use qskj 03 table structure for table test drop table if exists test create table test id int 10 not null auto increment comment 主鍵 username v...