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;