Quickly modify the table structure of a MySQL table

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.