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

相关推荐
虚伪的空想家7 小时前
记录次etcd故障,fatal error: bus error
服务器·数据库·k8s·etcd
韩立学长8 小时前
【开题答辩实录分享】以《植物爱好者交流平台的设计与实现》为例进行答辩实录分享
spring boot·后端·mysql
笨手笨脚の8 小时前
Mysql 的锁机制
数据库·mysql··死锁·间隙锁
老友@8 小时前
一次由 PageHelper 分页污染引发的 Bug 排查实录
java·数据库·bug·mybatis·pagehelper·分页污染
hzk的学习笔记8 小时前
Redisson解锁失败,watchdog会不会一直续期下去?
数据库·redis·缓存
合作小小程序员小小店8 小时前
web网页开发,在线%商城,电商,商品购买%系统demo,基于vscode,apache,html,css,jquery,php,mysql数据库
开发语言·前端·数据库·mysql·html·php·电商
TDengine (老段)9 小时前
TDengine 字符串函数 CONCAT 用户手册
java·数据库·tdengine
一 乐9 小时前
旅游|内蒙古景点旅游|基于Springboot+Vue的内蒙古景点旅游管理系统设计与实现(源码+数据库+文档)
开发语言·前端·数据库·vue.js·spring boot·后端·旅游
星光一影9 小时前
基于SpringBoot智慧社区系统/乡村振兴系统/大数据与人工智能平台
大数据·spring boot·后端·mysql·elasticsearch·vue
bing.shao9 小时前
如何降低redis哈希值冲突概率
数据库·redis·哈希算法