Add fields to the specified database location

Source: Internet
Author: User
Tags mysql tutorial

Add fields to the specified position in the database tutorial
Mysql tutorial> -- add a field to a database at a specified location
Mysql> drop table if exists t;
Query OK, 0 rows affected (0.06 sec)

Mysql> create table t (age int, address varchar (50 ));
Query OK, 0 rows affected (0.06 sec)

Mysql> desc t;
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Field | Type | Null | Key | Default | Extra |
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Age | int (11) | YES | NULL |
| Address | varchar (50) | YES | NULL |
+ --------- + ------------- + ------ + ----- + --------- + ------- +
2 rows in set (0.02 sec)

Mysql> alter table t add column name varchar (20) after age;
Query OK, 0 rows affected (0.16 sec)
Records: 0 Duplicates: 0 Warnings: 0

Mysql> desc t;
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Field | Type | Null | Key | Default | Extra |
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Age | int (11) | YES | NULL |
| Name | varchar (20) | YES | NULL |
| Address | varchar (50) | YES | NULL |
+ --------- + ------------- + ------ + ----- + --------- + ------- +
3 rows in set (0.00 sec)

Mysql> alter table t add column id int FIRST;
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0

Mysql> desc t;
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Field | Type | Null | Key | Default | Extra |
+ --------- + ------------- + ------ + ----- + --------- + ------- +
| Id | int (11) | YES | NULL |
| Age | int (11) | YES | NULL |
| Name | varchar (20) | YES | NULL |
| Address | varchar (50) | YES | NULL |
+ --------- + ------------- + ------ + ----- + --------- + ------- +
4 rows in set (0.00 sec)

Mysql>

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.