数据库MySQL--修改数据表

时间:2023-11-21 18:46:56

创建数据库::create database 数据库名;

如果数据不存在则创建,存在不创建:Create database if not exists 数据库名 ;

删除数据库::drop database 数据库名;

修改数据表::关键字alter

修改数据表名:

:alter table 数据表名 rename to 新表名;

删除数据表中i字段(关键字:drop):

:alter table 数据表名 drop i;

向数据表添加k 字段,并定义类型(关键字:add):

:alter table 数据表名 add k int;

向数据表添加k 字段到指定字段名后,并定义类型(关键字:after):

:alter table 数据表名 add k int after m;

  # 设置为第一列 关键字为first

修改数据表字段名的数据类型(关键字:modify):

:alter table 数据表名 modify 字段名 新数据类型;

修改数据表字段名:(关键字:change):

## 关键字后紧跟这是要修改的字段名,其后是指定的新名字及新类型 ##

:alter table 数据表名 change 就名字 新名字 字段类型;

修改数据表字段名时,设置字段默认值(关键字:not null default):

:alter table 数据表名 modify 字段名 数据类型 not null default 默认值;

修改字段默认值:

:alter table 数据表名 alter 字段名 set default 新默认值;