插入,修改,删除数据库表(DDL)

2021/12/13 2:18:25

本文主要是介绍插入,修改,删除数据库表(DDL),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

-- 修改表的结构:
-- 增加一列:
alter table s_student add score double(5,2); -- 增加一列score 5指的是总位数 2指的是小数的位数

运行结果:

 

 

 -- 往score里添加数据

update s_student set score = 123.5678 where son = 1;  -- 在son等于1里添加成绩

运行结果:

 

 

 注:因为score double(5,2)5指的是总位数 2指的是小数的位数,四舍五入最后为123.57

 

如果想要score这一列,添加到最前面,可以这样:

alter table s_student add score double(5,2)first;

运行结果:

 

 

将score这一列,添加到谁(sex)后面:

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

运行结果:

 

 

 

 

想要删除一列:

 

 

alter table s_student drop score;

运行结果:

 

 

想要修改(modify,change)一列:

alter table s_student modify score float(4,1);  -- modify修改是列的类型定义,但是不会改变列的名字

运行结果:

 

 注:本来是double(5,2)现在是float(4,1)

 

 

 

 

alter table s_student change score score1 double(5,1);  -- change修改列名和列的类型定义

运行结果:

 

 注:score名字被修改为score1,float(4,1)被修改为double(5,1)

 

删除表:

drop table s_student;

 

这里全都是对数据库对象进行操作,属于DDL

 



这篇关于插入,修改,删除数据库表(DDL)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程