mysql alter modify the name of the table structure to increase the column

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags change default delete drop key mysql mysql tutorial name

Alter alter the name of the table alter the name of the table structure to increase the column

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

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

alter table table_name
add column_name datatype
To delete a column in a table, use the following syntax:

alter table table_name
drop column column_name
Note: Some database tutorial systems do not allow this way of dropping columns in database tables (drop column column_name).

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

alter table table_name
alter column column_name datatype

Look at the alert detailed 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:
Increase the field:

alter table dbname add column <field name> <field option>


Modify fields:

alter table dbname change <old field name> <new field name> <option>


Delete field:
alter table dbname drop column <field name>

Example 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)

Take a look at the examples

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.