MySQL alter modify Word name Table name structure Add column

Source: Internet
Author: User
Tags mysql tutorial create database

MySQL Tutorial alter modify Word 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
If you want to add columns to the table, use the following syntax:

ALTER TABLE TABLE_NAME
Add column_name datatype
To delete a column from a table, use the following syntax:

ALTER TABLE TABLE_NAME
Drop Column column_name
Note: Some database tutorial systems do not allow such a way to delete columns in a database table (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

Take a look at alert detail syntax


Alter_specification:
Add [column] create_definition [i | 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


To modify the database structure:
Add fields:

ALTER TABLE dbname add column < field name >< field Options >


To modify a field:

ALTER TABLE dbname change < old field name > < new field name >< option >


To delete a field:
ALTER TABLE dbname drop column < field name >

Instance action:

>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 example

mysql> ALTER TABLE topics change Hotico hot_count int (4);
Mysql> ALTER TABLE topics ALTER HOT_COUNT set default 1;

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.