How can I add fields to MySQL? This is a problem that many new users have just mentioned. The following describes how to add and delete fields in MySQL.
Add a MySQL field:
- Alter table 'user _ movement_log'
- Add column GatewayId int not null default 0 AFTER 'regionid' (AFTER which field is added)
-
Delete field:
- alter table `user_movement_log` drop column Gatewayid
-
Adjust the field order:
- Alter table 'user _ movement_log 'CHANGE 'gatewayid' int not null default 0 AFTER RegionID
-
- // Primary key
-
- Alter table tabelname add new_field_id int (5) unsigned default 0 not null auto_increment, add primary key (new_field_id); // add a new column
-
- Alter table t2 add d timestamp;
- Alter table infos add ex tinyint not null default '0'; // delete a column
-
- Alter table t2 drop column c; // rename a column
-
- Alter table t1 change a B integer;
- // Change the column type
-
- Alter table t1 change B bigint not null;
- Alter table infos change list tinyint not null default '0 ';
- // Rename the table
-
- Alter table t1 rename t2; add an index
-
- Mysql> alter table tablename change depno int (5) not null;
- Mysql> alter table tablename add index name (field name 1 [, field name 2…]);
- Mysql> alter table tablename add index emp_name (name); add the index with the primary keyword
-
- Mysql> alter table tablename add primary key (id); add an index with unique restrictions
-
- Mysql> alter table tablename add unique emp_name2 (cardnumber); delete an index
-
- Mysql> alter table tablename drop index emp_name; modify the table:
-
Add field:
- 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 a field:
-
- Mysql> alter table table_name DROP field_name;
How MySQL defines foreign keys
Detailed description of the actual configuration of SlowLog in MySQL
Provides you with an in-depth understanding of MYSQL string connection
MySQL Field Type
Mysql foreign Key Usage Analysis