SQL Server、达梦数据库 存储过程:两个表(一对多)数据合并到一个表

使用存储过程和游标处理两个表(一对多)的数据到一个表中,涉及到存储过程调用另一个存储过程技术点,记录SQL Server、达梦两种数据库的实现。

测试表

复制代码
--创建测试表 person
create table person
(
	id int not null,
	name varchar(20),
	primary key(id)
);

--创建测试表 telephone
create table telephone
(
	id int not null,
	toolname varchar(20),
	number varchar(20)
);

--创建测试表 person_telephone
create table person_telephone
(
	id int not null,
	name varchar(20),
	tel varchar(200),
	primary key(id)
);

--插入测试数据
insert into person(id,name) values(1,'李小龙');
insert into person(id,name) values(2,'张大富');
insert into telephone(id,toolname,number) values(1,'电话','010-66666666');
insert into telephone(id,toolname,number) values(1,'手机','13866666666');
insert into telephone(id,toolname,number) values(1,'小灵通','5879325');
insert into telephone(id,toolname,number) values(2,'电话','010-55555555');

go

存储过程脚本

创建两个存储过程:

  • proc1:提取 telephone 的联系数据
  • proc2:调用 proc1 并向person_telephone插入数据

完整阅读:
https://www.laobingbiji.com/page/202404030842010000000010691999.html

相关推荐
计算机毕设VX:Fegn08951 天前
计算机毕业设计|基于springboot + vue高校实验室教学管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
哈里谢顿1 天前
mysql基础面试题
mysql
net3m331 天前
websocket下发mp3帧数据时一个包被分包为几个子包而导致mp3解码失败而播放卡顿有杂音或断播的解决方法
开发语言·数据库·python
TG:@yunlaoda360 云老大1 天前
华为云国际站代理商WeLink的资源与工具支持具体有哪些?
服务器·数据库·华为云
TG:@yunlaoda360 云老大1 天前
华为云国际站代理商申请跨账号代维权限的流程复杂吗?
网络·数据库·华为云
云老大TG:@yunlaoda3601 天前
华为云国际站代理商MSGSMS的服务质量如何?
大数据·数据库·人工智能·华为云
热爱专研AI的学妹1 天前
【高级教程】联网搜索网页阅读api使用cURL从接口调试到复杂场景实战
服务器·数据库·人工智能·搜索引擎
橙汁味的风1 天前
5数据库完整性
数据库
汽车仪器仪表相关领域1 天前
ZDT-I 伺服电机测试系统
数据库·功能测试·安全·机器人·压力测试·可用性测试