Modification of MySQL database table structure

Modification of MySQL database table structure


Application scenario: When a table in a database has a structure and data is already stored, the entire table should not be deleted.
If you need to modify the type, field name or attribute of some fields of the table, you can use alter to modify

1. Increase column

alter table 表名 add 列名 类型(长度)约束;

Insert picture description here


2. Modify the existing column type, length and constraints

alter table 表名 modify 列名 类型(长度) 约束;

Insert picture description here
note:modify只能修改属性 不能修改列名


3. Modify the existing column name

alter table表名 change 旧列名 新列名 类型(长度)约束;

Insert picture description here


4. Delete existing columns

alter table 表名 drop 列名;

Insert picture description here


Guess you like

Origin blog.csdn.net/qq_45797116/article/details/115216708