34,576
社区成员
发帖
与我相关
我的任务
分享
create procedure my_proc
as
begin
declare @id1 as int
declare @id2 as int
declare @id3 as int
select @id1 = top 1 id1 from A where num1 > 某个值 order by newid()
select @id2 = top 1 id2 from B where num2 > 某个值 order by newid()
select @id3 = isnull(max(id3),0) + 1 from C
insert into C select @id3,@id1,@id2
end
go
exec my_proc
使用存储过程,每执行一次插入一条记录.
随机:
select top 1 id1 from A where num1 > 某个值 order by newid()
select top 1 id2 from A where num1 > 某个值 order by newid()
至于你的插入如何搞就不知道了,如ID3怎么赋值?