IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_biztype_insert]') AND type = 'TR')
DROP TRIGGER [dbo].[mps_biztype_insert]
GO
CREATE trigger [dbo].[mps_biztype_insert] on [dbo].[mps_biztype] for insert as
begin
    declare
       @maxcard  int,
       @numrows  int,
       @numnull  int,
       @errno    int,
       @errmsg   varchar(255)

    select  @numrows = @@rowcount
    if @numrows = 0
       return

declare @cmpid int 
select top 1 @cmpid = biz_cmpid from  inserted  
set @cmpid = isnull(@cmpid,0) 

 update mps_tableupdated set tu_updated=0 where  tu_table='mps_biztype' and tu_cmpid=@cmpid 
insert into mps_sync(sk_type,sk_bizid,sk_objid,sk_operation,sk_tag2) 
select 20 , biz_id , biz_id , 1 , 0 from inserted  

-- 将一些规则加入query
insert into mps_biztype_query(bql_bizid,bql_caption,bql_sql,bql_orderby,bql_status,bql_order) 
select biz_id,'待审业务','ord_finished=1','ord_date desc',0,1 from inserted 
insert into mps_biztype_query(bql_bizid,bql_caption,bql_sql,bql_orderby,bql_status,bql_order) 
select biz_id,'我发起的','ord_createcuid=@useruid and ord_finished>=1 and ord_finished<=10','ord_date desc',0,2 from inserted 
insert into mps_biztype_query(bql_bizid,bql_caption,bql_sql,bql_orderby,bql_status,bql_order) 
select biz_id,'全部数据','ord_finished>=1','ord_date desc',0,3 from inserted 
    return

/*  Errors handling  */
error:
    -- raiserror @errno @errmsg
    rollback  transaction
end