MySQL Modify Add Delete table field

Source: Internet
Author: User

Add a field to a table ALTER TABLE name the type of the Add Field name fields

Example: ALTER TABLE table1 add transactor varchar (ten) not Null;

ALTER TABLE table1 add ID int unsigned not Null auto_increment primary key

How to add a field after a specified field in the MySQL database:

ALTER TABLE Newexample add address varchar (a) after stu_id;

Modifying the field type of a table ALTER table name MODIFY COLUMN field type definition;

Example: ALTER TABLE chatter_users MODIFY COLUMN IP VARCHAR (50);

Modify the field name of the table ALTER TABLE name change the original field name the type of the new field name segment

example: ALTER TABLE student change Physics Physisc char (TEN) NOT NULL

Delete a table field ALTER TABLE name drop column field name

Example: Alter TABLE ' user_movement_log ' drop column Gatewayid

Adjust table order: ALTER table ' user_movement_log ' change ' Gatewayid ' gatewayid ' int not null default 0 after RegionID

table rename ALTER TABLE name rename present table name;

Example: ALTER TABLE t1 rename T2;

Delete table data Delete from table name where (condition) ID is not starting from 1, TRUNCATE table name ID is starting from 1

Example of creating a table

CREATE TABLE hlh_message (

ID Int (one) not NULL auto_increment COMMENT ' health table ID ',

Title varchar (+) not NULL COMMENT ' health title ',

Hlh_url text DEFAULT NULL COMMENT ' picture address ',

BeWrite VARCHAR () not NULL COMMENT ' description ',

Content VARCHAR (+) not NULL COMMENT ' contents ',

Type tinyint (1) Not NULL DEFAULT ' 0 ' COMMENT ' health Knowledge 0 Health Consulting 1 ',

Create_time date DEFAULT NULL COMMENT ' time to publish message ',

PRIMARY KEY (ID)

) Engine=innodb DEFAULT Charset=utf8 comment= ' health table '

MySQL Modify Add Delete table field

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.