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

相关推荐
小叶子来了啊4 分钟前
信息系统运行管理员:临阵磨枪版
运维·服务器·数据库
数据库幼崽28 分钟前
MySQL 8.0 OCP 1Z0-908 131-140题
数据库·mysql·ocp
北漂老男孩1 小时前
主流数据库运维故障排查卡片式速查表与视觉图谱
运维·数据库
源码云商1 小时前
基于SpringBoot的校园周边美食探索及分享平台【附源码+数据库+文档下载】
数据库·spring boot·美食
爱编程的小新☆1 小时前
【MySQL】数据库三大范式
数据库·mysql
随心............1 小时前
MySQL的触发器
数据库·mysql
GUIQU.2 小时前
【MySQL】项目实践
数据库·mysql·项目实践
XINGTECODE2 小时前
海盗王3.0的数据库3合1并库处理方案
数据库·海盗王
滴滴哒~3 小时前
实验九视图索引
数据库