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

相关推荐
RestCloud15 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud15 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence17 小时前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
Java水解19 小时前
Mysql查看执行计划、explain关键字详解(超详细)
后端·mysql
知其然亦知其所以然1 天前
MySQL 社招必考题:如何优化查询过程中的数据访问?
后端·mysql·面试
DemonAvenger1 天前
NoSQL与MySQL混合架构设计:从入门到实战的最佳实践
数据库·mysql·性能优化
程序新视界1 天前
如何在MySQL中创建聚集索引?
mysql
AAA修煤气灶刘哥1 天前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
程序新视界2 天前
学习MySQL绕不开的两个基础概念:聚集索引与非聚集索引
mysql
RestCloud2 天前
跨境数据传输:ETL如何处理时区与日期格式差异
mysql·api