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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值