Mysql alter name table name structure add Column

Source: Internet
Author: User
Tags mysql tutorial

Mysql tutorial alter name table name structure add Column

Alter table statement
The alter table statement is used to add, modify, or delete columns in an existing table.

SQL alter table syntax
To add columns to a table, use the following syntax:

Alter table table_name
Add column_name datatype
To delete columns in a table, use the following syntax:

Alter table table_name
Drop column column_name
Note: Some database tutorial systems do not allow this method of deleting columns in database tables (drop column column_name ).

To change the data type of columns in a table, use the following syntax:

Alter table table_name
Alter column column_name datatype

Take a look at the detailed alert syntax


Alter_specification:
Add [column] create_definition [first | after column_name]
Or add index [index_name] (index_col_name ,...)
Or add primary key (index_col_name ,...)
Or add unique [index_name] (index_col_name ,...)
Or alter [column] col_name {set default literal | drop default}
Or change [column] old_col_name create_definition
Or modify [column] create_definition
Or drop [column] col_name
Or drop primary key
Or drop index index_name
Or rename [as] new_tbl_name
Or table_options
Eg:


Modify the database structure:
Add field:

Alter table dbname add column <field Name> <field Options>


Modify Field:

Alter table dbname change <old field Name> <new field Name> <option>


Delete field:
Alter table dbname drop column <field Name>

Instance operation:

> Create database office;
> Use office;
Mysql> create table personal (
-> Member_no char (5) not null,
-> Name char (,
-> Birthday date,
-> Exam_score tinyint,
-> Primary key (member_no)
-> );

Query OK, 0 rows affected (0.01 sec)

 

Look at the instance

Mysql> alter table topics change hotico hot_count int (4 );
Mysql> alter table topics alter hot_count set default 1;

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.