存储过程、事务和触发器 三者之间都可以嵌套吗?

解决方案 »

  1.   

    --例如:
    两个存储过程间事务的相互调用
    (http://topic.csdn.net/u/20080305/13/e40e74ca-1491-4e48-8824-d2fcfc894bd8.html?seed=2131186353)
      

  2.   


    create proc proc_OnHour
    @TableName varchar(17),
    @objCode varchar(12),
    @objUnit char(3)asprint @objUnitprint @TableNameprint @objCodeexec('create trigger tgr'+@objCode+'
    on '+@TableName+' for insert
    as
    declare @iavg decimal
    declare @imax decimal
    declare @imin decimal
    declare @iUnit char(3)
    declare @time datetime
    declare @wry char(12)
    declare @pfk char(15)set @wry = '+@objCode+'set @iUnit = '''+@objUnit+'''
    select @iavg = avg(t0.流量),@imax = max(t0.流量),@imin = min(t0.流量),@time = max(t0.监测时间) from 
        '+@TableName+' t0,inserted i where
        datediff(hour,t0.监测时间,i.监测时间)=0 
        and t0.排放口编码 = i.排放口编码 select @pfk = i.排放口编码 from inserted i delete from 污染源_废水排放口小时数据 where datediff(hour,日期时间,@time)=0
    insert into 污染源_废水排放口小时数据(
        污染源编码,
        排放口编码,
        日期时间,
        最小流量,
        最小流量_单位,
        平均流量,
        平均流量_单位,
        最大流量,
        最大流量_单位
    ) values(
        @wry,
        @pfk,
        @time,
        @imin,
        @iUnit,
        @iavg,
        @iUnit,
        @imax,
        @iUnit
    )
    ')