插入,修改,删除数据库表(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)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-02springboot项目无法注册到nacos-icode9专业技术文章分享
- 2024-06-26结对编程到底难不难?答案在这里
- 2024-06-19《2023版Java工程师》课程升级公告
- 2024-06-15matplotlib作图不显示3D图,怎么办?
- 2024-06-1503-Loki 日志监控
- 2024-06-1504-让LLM理解知识 -Prompt
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)