mysql adds modify field types and delete field types

  • 2020-06-23 02:07:04
  • OfStack

MySQL Add fields:


alter table `user_movement_log` 

Add column GatewayId int not null default 0 AFTER `Regionid` ( After which field to add )

Delete fields:


alter table `user_movement_log` drop column Gatewayid

Adjust field order:


ALTER TABLE `user_movement_log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID 

// A primary key  

alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);// increase 1 A new column  

alter table t2 add d timestamp; 

alter table infos add ex tinyint not null default '0';// Delete the column  

alter table t2 drop column c;// Rename columns  

alter table t1 change a b integer; 

// Change the type of the column  

alter table t1 change b b bigint not null; 

alter table infos change list list tinyint not null default '0'; 

// Rename table  

alter table t1 rename t2; indexed  

mysql> alter table tablename change depno depno int(5) not null; 

mysql> alter table tablename add index  Index name  ( The field name 1[ The field name 2  ... ]); 

mysql> alter table tablename add index emp_name (name); Add the index of the primary keyword  

mysql> alter table tablename add primary key(id); Add only 1 Index of restricted conditions  

mysql> alter table tablename add unique emp_name2(cardnumber); Delete an index  

mysql>alter table tablename drop index emp_name; Modify the table: 

Add fields:


mysql> ALTER TABLE table_name ADD field_name field_type; Modify the original field name and type:  

mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type; Delete fields:  

mysql> ALTER TABLE table_name DROP field_name;

Related articles: