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;