create procedure mysp7 @trantype varchar(20)
AS
DECLARE @error varchar(20)
DECLARE @TranName VARCHAR(20)
SELECT @TranName = 'MyTransaction'
BEGIN TRANSACTION @TranName
if @trantype = ''
set @error = '1'
if @trantype = 'begin' begin
select a.ename,a.age,a.password,a.username into #temp2 from 表A as a
insert 表B
select * from #temp2
set @error = '0'
end
if @error = '0'
COMMIT TRANSACTION MyTransaction
if @error = '1'
rollback transaction
------解决方案-------------------- 如果列数本来不一致,就不能用select * 要用类似的写法:
insert into b(id,name,value)
select id,name,value from a ------解决方案--------------------
楼上正解,鉴定完毕。 ------解决方案-------------------- insert 表B
select * from #temp2
insert into 表B (字段1,字段2,..字段N)
select (字段1、字段2...字段N) from #temp2
这样最稳妥 ------解决方案-------------------- 。。。慢太多了。。 ------解决方案-------------------- insert into 表B(ename,age,password,username)
select ename,age,password,username from 表A ------解决方案-------------------- 正解 ------解决方案-------------------- insert into B(1,2,3,4,5) select 1,2,3,4,5 from # temp2
1,2,3,4,5代表字段
這樣應該ok