Mysql modified difference field do not change and modify the

The following table describes:
mysql> desc test;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id    | int(10)  | YES  |     | NULL    |       |
| name  | char(10) | YES  |     | NULL    |       | +-------+----------+------+-----+---------+-------+
2 rows in set (0.01 sec)

MySQLIn changeand modifythe difference

  • Change the column name change: alter table 表名 change 旧列名 新列名 类型
mysql> alter table test change name name_1 int(10);
Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc test; +----------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+---------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name_1 | int(10) | YES | | NULL | | +----------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec)

Just change the column attribute change: alter table 表名 列名 列名 类型the same column name written twice

mysql> alter table test change  name_1 name_1 char(32);
Query OK, 0 rows affected (0.15 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc test; +----------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+----------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name_1 | char(32) | YES | | NULL | | +----------+----------+------+-----+---------+-------+ 2 rows in set (0.01 sec)

Change the column properties modify: alter table 表名 列名 类型

mysql> desc test;
+----------+----------+------+-----+---------+-------+
| Field    | Type     | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| id       | int(10)  | YES  |     | NULL    |       |
| name_1 | char(32) | YES  |     | NULL    |       |
+----------+----------+------+-----+---------+-------+
2 rows in set (0.01 sec) mysql> alter table test modify name_1 int(10); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc test; +----------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+---------+------+-----+---------+-------+ | id | int(10) | YES | | NULL | | | name_1 | int(10) | YES | | NULL | | +----------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
change can change the column names and types (each time the new column names and column names written legacy, even if the two column name has not changed, just changed the type)
modify column attributes can be changed only you need to write a column name, than change the easy way point


Guess you like

Origin www.cnblogs.com/sunshinekevin/p/12325146.html