MySQL alter modify the length type of a field SQL statement

Source: Internet
Author: User

MySQL Modify field length

ALTER TABLE news Modify column title varchar (130);

ALTER TABLE name modify column field name type;

For example: the title field in the news table is 100 characters in length and is changed to 130 characters

ALTER TABLE news Modify column title varchar (130);

Modify a field type

The Address Table City field in the database is varchar (30)

Modifying a type can be used (carefully modifying the type may result in an error in the original data)

Mysql> ALTER TABLE address modify column City char (30);

The length standard statement for modifying a field is:

ALTER TABLE name modify column (field 1 type, field 2 type
.........) ;
Write the fields you need to modify without writing.
If there is a table name news, field name tags, original tags for char (20), now to be changed to char (200), you can write:

ALTER TABLE ' phome_enewstags ' modify column TagName char (200);
ALTER TABLE ' phome_ecms_news ' modify column filename varchar (100);

Execute it!

You can also use the following instructions

ALTER TABLE SMS_BILLBOOK_TJ change tj_type tj_type varchar (100);
ALTER TABLE name change column names varchar (100);

MySQL alter usage

1: Delete Column

ALTER table "table name" DROP "column name"

2: Adding columns

ALTER table "table name" ADD "column name" INT not NULL COMMENT ' annotation description '

3: Modify the column's type information

ALTER table "table name" Change "column name" new column name (this can be used with the same name as the original column) "BIGINT not NULL COMMENT ' comment description '

4: Renaming a column

ALTER table "table name" Change "column Name" "New column name" BIGINT not NULL COMMENT ' comment description '

5: Renaming tables

ALTER table "table name" RENAME "Table new name"

6: Delete the primary key in the table

Alter table "table name" Drop PRIMARY key

7: Add primary key

ALTER TABLE sj_resource_charges ADD CONSTRAINT pk_sj_resource_charges PRIMARY KEY (resid,resfromid)

8: Add index

ALTER TABLE sj_resource_charges Add index index_name (NAME);

9: Add a unique restricted condition index

ALTER TABLE sj_resource_charges Add unique emp_name2 (cardnumber);

10: Delete Index

ALTER TABLE tablename DROP INDEX emp_name;

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.