[MySQL] DDL_ modify, delete database table

1. Data Definition Language

DDL, the full name is Data Definition Language, the Chinese name is Data Definition Language . DDL is mainly used to create, modify and delete database objects (databases, tables, indexes, views, triggers , stored procedures, functions). It mainly includes

  • CREATE: create database objects
  • ALTER: modify database objects
  • DROP: delete database objects

Different from the data manipulation language, the data manipulation language operates on the data in the database table , and the data definition language operates on the database table .

2. Add a column

The following will modify the structure of the table and add a column, the keyword used is alter

alter table t_student add score double(5,2);

 

Double belongs to the floating-point type in the column type . Unlike the integer type, the width of the floating-point type will not be automatically expanded. For example: score double(5,2) means the total width is 5 digits, the decimal part is 2 digits, and will not be automatically expanded.
 

3. Delete a column

The grammatical structure is: alter table table name drop field name;

For example: delete the score column (score)

-- 删除一列
alter table t_student drop score;

After running this SQL, the score column will be deleted.

4. Add columns anywhere in the table

1. Add the score column (score) to the first column of the list, just write first at the end of the SQL:

-- 将列添加到第一列(最前面)
alter table t_student add score double(5,2) first;

2. Add the score column (score) to the end of a column in the table, and write the after field name at the end of the SQL .

First delete the score column (score):

alter table t_student drop score;

For example: add the score column (score) to the column named sex (gender):

alter table t_student add score double(5,2) after sex;

Guess you like

Origin blog.csdn.net/hold_on_qlc/article/details/129657743