quickly modify the table structure of a MySQL table-- excerpt from "MySQL Management"
ALTER table name MODIFY column name data type; This command can modify the table structure
In addition, you can modify the table structure as follows:
First create a table, as follows:
> CREATE table t1 (id int, name varchar (5), RMB decimal (9,1));
If you want to modify the Name column varchar (10), you can do this: ALTER TABLE T1 modify name varchar (7);
You can also do the following:
1. View the table structure as follows:
> use test;> desc t1;+-------+--------------+------+-----+---------+-------+| field | type | null | key | default | extra |+-------+--------------+------+-----+---------+-------+| id | int (one) | YES | | null | | | name | varchar (5) | YES | | null | | | rmb | decimal (9,1) | yes | | null | |+-------+--------------+------+- ----+---------+-------+3 rows in set (0.00&nbsP;SEC)
2. Create a temporary table and set the varchar to 10:
> CREATE table t1_tmp (ID int, name varchar (), RMB decimal (9,1));
3, replace the. FRM table structure file
> Flush tables with read lock; Lock the table first and put the table open to avoid data loss. > System cp/usr/local/mariadb/var/test/t1_tmp.frm/usr/local/mariadb/var/test/t1.frm
4. Unlock the Lock
> Unlock tables;
5. View table structure
> Show CREATE TABLE t1\g*************************** 1. Row *************************** table:t1create table:create Table ' t1 ' (' id ' int (one) DEFAULT NULL, ' name ' Varch AR (TEN) default NULL, ' $ ' decimal (9,1) default null) Engine=innodb default charset=utf81 row in Set (0.00 sec)
You can see the varchar (10) of the Name column.
6. Insert Bar Data test
> INSERT into T1 values (2, ' Hechuangyang ', 3.8); If you don't make an error, the change is successful.
Quickly modify the table structure of a MySQL table