mysql-Modifying a table

Source: Internet
Author: User

A modified table name

ALTER TABLE old_table_name Rename [to] New_table_name

Eg:alter Table T_dept

RENAME tab_dept;

Two add fields

1) Add field at the last position of the table

ALTER TABLE table_name

ADD Property Name Property type

Eg:alter Table T_dept

ADD Descri varchar (20);

2) Add a field to the first position in the table

ALTER TABLE table_name

ADD Property Name property type first;

3) Add a field after the specified field in the table

ALTER TABLE table_name

ADD Property Name Property type

After property name;

Three delete fields

ALTER TABLE table_name

DROP attribute name;


Four modified fields


1) Modify the data type of the field

ALTER TABLE table_name

MODIFY Property name Data type

Eg:alter Table T_dept

Modify Deptno varchar (20);

2) Change the name of the field

ALTER TABLE table_name

Change old property name new property name old data type

Eg:alter Table T_dept

Change LOC location varchar (40);

3) Modify the name and attributes of the field at the same time

ALTER TABLE table_name

Change old property name new property name new data type

Eg:alter Table T_dept

Change LOC location varchar (20);

4) Modify the order of the fields

ALTER TABLE table_name

MODIFY Property name 1 data type first| After property name 2

Eg:alter Table T_dept

Modify Deptno Int (one) after dname;













This article from the "Walk and Stop" blog, reproduced please contact the author!

mysql-Modifying a table

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.