MySQL database table modifies the type of a column

Source: Internet
Author: User

listed below:
1. Add a field
ALTER TABLE user add COLUMN new1 VARCHAR default null;//Add a field that defaults to null
ALTER TABLE user add COLUMN new2 VARCHAR (a) not NULL; Add a field that cannot be empty by default
2. Delete a field
ALTER TABLE user DROP COLUMN new2; Delete a field
3. Modify a field
ALTER TABLE user MODIFY New1 VARCHAR (10); Modify the type of a field
ALTER TABLE user change new1 new4 int; To modify the name of a field, be sure to re -

//PRIMARY key
ALTER TABLE tabelname add new_field_id int (5) unsigned default 0 NOT NULL auto_increment, add primary key (New_field_i d);
//Add a new column
ALTER TABLE T2 add d timestamp;
ALTER TABLE infos add ex tinyint NOT null default ' 0′;
//Delete columns
ALTER TABLE T2 drop column C;
//Rename columns
ALTER TABLE T1 change a b integer;
//Change the type of column
ALTER TABLE T1 change b b bigint not null;
ALTER TABLE infos change list list tinyint not null default ' 0′;
//Rename table
ALTER TABLE t1 rename T2;
Gazzo Primer
mysql> ALTER TABLE tablename change depno depno int (5) is not null;
mysql> ALTER TABLE tablename ADD index index name (field name 1[, field Name 2 ...]);
mysql> ALTER TABLE tablename Add index Emp_name (name);
index of the plus primary keyword
mysql> ALTER TABLE tablename ADD PRIMARY key (ID);
index with unique restriction criteria
mysql> ALTER TABLE tablename add unique emp_name2 (cardnumber);
Delete an index
mysql>alter Table tablename DROP index emp_name;
Add Field:
mysql> ALTER TABLE table_name ADD field_name field_type;
Modify the original field name and type:
mysql> ALTER TABLE table_name change old_field_name new_field_name field_type;
To delete a field:
mysql> ALTER TABLE table_name DROP field_name;
MySQL Modify field length
ALTER TABLE name modify column field name type;
For example
The User table name field in the database is varchar (
can be used
ALTER TABLE user modify column name varchar ();

Or

ALTER TABLE user modify column name datetime;

MySQL database table modifies the type of a column

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.