Quickly modify the table structure of a MySQL table - excerpted from "MySQL Management" ALTER TABLE table name MODIFY column name data type; This command can modify the table structure. In addition, you can also 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 to 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(11) | YES | | NULL | | | name | varchar(5) | YES | | NULL | | | rmb | decimal(9,1) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) 2. Create a temporary table and set varchar to 10: > create table t1_tmp (id int, name varchar(10), rmb decimal(9,1)); 3. Replace the .frm table structure file > flush tables with read lock; Lock the table first before opening it to avoid data loss. > system cp /usr/local/mariadb/var/test/t1_tmp.frm /usr/local/mariadb/var/test/t1.frm 4. Unlock > unlock tables; 5. View the table structure > show create table t1\G *************************** 1. row *************************** Table: t1 Create Table: CREATE TABLE `t1` ( `id` int(11) DEFAULT NULL, `name` varchar(10) DEFAULT NULL, `rmb` decimal(9,1) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec) You can see the varchar(10) in the name column. 6. Try inserting a piece of data > insert into t1 values(2,'hechuangyang',3.8); If no error is reported, the modification is successful. The above is the details of how to quickly modify the table structure of MySQL. For more information about modifying the table structure of MySQL, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: WeChat applet implements waterfall flow paging scrolling loading
>>: Front-end JavaScript thoroughly understands function currying
The data URI scheme allows us to include data in a...
1. [admin@JD ~]$ cd opt #Enter opt in the root di...
Nginx, pronounced "engine x," is an ope...
Here are some common MySQL commands for you: -- S...
Rendering Example Code Today we are going to use ...
Preface In the early stages of some projects, dev...
When the scroll bar is pulled down, the floating ...
Adaptive layout is becoming more and more common i...
There are two files a.htm and b.htm. In the same d...
The inline-block property value becomes very usef...
eureka: 1. Build a JDK image Start the eureka con...
After setting the iframe's src to 'about:b...
Because I wrote a Python program and intensively ...
Table of contents Scene Introduction Deep respons...
The table creation command requires: The name of...