主表:
T1:主键C0自动增1
内容:
C0 Name Sex
1 王 男
2 李 女从表:主键自动增1
T2:
Id C0 work_n work_d要求在从表中添加每一主表人员一组从表数据如下
work_n work_d
办公 200601
财务 200602
汽车 200504
T1:主键C0自动增1
内容:
C0 Name Sex
1 王 男
2 李 女从表:主键自动增1
T2:
Id C0 work_n work_d要求在从表中添加每一主表人员一组从表数据如下
work_n work_d
办公 200601
财务 200602
汽车 200504
if(@@error=0)
begin
set @returnid=SCOPE_IDENTITY( )
insert into T2(C0,work_n,work_d) select @returnid,'办公',200601
union all select @returnid,'财务',200602
union all select @returnid,'汽车',200604
end
1 1 办公 200601
2 1 财务 200602
3 1 汽车 200504
4 2 办公 200601
5 2 财务 200602
6 2 汽车 200504
insert into #t select 1,'王'
union all select 2,'李'select * from #tcreate table #t1(id int,work_n varchar(10),work_d int)
insert into #t1 select 1,'办公',200601
union all select 2,'财务',200602
union all select 3,'汽车',200604create table #t2(id int identity,C0 int,work_n varchar(10),work_d int)insert into #t2(C0,work_n,work_d) select a.id,b.work_n,b.work_d from #t a,#t1 b order by a.idselect * from #t2