zoukankan      html  css  js  c++  java
  • 触发器

    --创建insert插入类型触发器
    if (object_id('tgr_product_insert', 'tr') is not null)
        drop trigger tgr_product_insert
    go
    create trigger tgr_product_insert
    on products
        for insert --插入触发
    as
            if exists(select * from inserted i where i.serial_number not in (select serial_number from wx_shop_product))      
             begin
        
     insert into  wx_shop_product ( [categoryId],[brandId],[sku] ,[productName] ,[erpName] ,[shortDesc],[unit_id]
          ,[unit] ,[weight] ,[description]
          ,[seo_title]  ,[seo_keywords] ,[seo_description]
          ,[recommended],[latest],[hotsale] ,[specialOffer]
          ,[costPrice] ,[marketPrice],[salePrice]
          ,[upselling]
          ,[stock]
          ,[importDate]
          ,[vistiCounts]
          ,[sort_id]
          ,[updateDate]
          ,[deleted]
          
          ,[integral]) 
               (select
             p.categoryid,'','',p.name,'',p.shortDesc,p.unit1_id,p.unit2_id,'',p.comment,'',
             '','',p.comment,'','','',0,0,0,'',p.standard,p.Inputdate,'',p.ifdiscount,p.Inputdate,p.deleted
             ,p.Integral
             
              from products p inner join  (select * from inserted ii where  ii.serial_number not in 
              (select serial_number from wx_shop_product)) p1  on p1.serial_number=p.serial_number)
           
             
             end
    go

    更新类触发器

    --创建insert更新类型触发器
    if (object_id('tgr_product_update', 'tr') is not null)
        drop trigger tgr_product_update
    go
    create trigger tgr_product_update
    on products
        for update --更新触发
    as
            if exists(select * from inserted i where i.serial_number not in (select serial_number from wx_shop_product))      
             begin
        
    update   wx_shop_product
    set 
      categoryId=p2.categoryid,brandId=p2.brandId,productName=p2.name,erpName=p2.erpName,
      shortDesc=p2.shortDesc,unit_id=p2.unit1_id,weight=p2.weight,description=p2.description,
      recommended=p2.recommended,latest=p2.isNew,hotsale=p2.isHot,specialOffer=p2.specialOffer,
      costPrice=p2.costPrice,marketPrice=p2.marketPrice,salePrice=p2.salePrice,upselling=p2.upselling,
      stock=p2.standard,importDate=p2.Inputdate,vistiCounts=p2.vistiCounts,sort_id=p2.ifdiscount,updateDate=updateDate,
      deleted=p2.deleted
           from  (select
             p.categoryid,'' as 'brandId' ,'' as 'sku',p.name,'' as 'erpName',p.shortDesc,p.unit1_id,p.unit2_id,'' as 'weight',
             '' as 'description',
             '' as 'seo_title','' as 'seo_keywords',p.comment,'' as 'recommended',p.isNew,p.isHot,0  as 'specialOffer',
             0 as 'costPrice',0 as 'marketPrice','' as 'salePrice' ,'' as 'upselling',p.standard, p.Inputdate,'' as 'vistiCounts',p.ifdiscount,p.deleted
             ,p.Integral
              from products p inner join  (select * from inserted ii where  ii.serial_number not in 
              (select serial_number from wx_shop_product)  ) p1  on p1.serial_number=p.serial_number) as p2
         where serial_number in (select serial_number from inserted )
              
             end
    go
  • 相关阅读:
    工序打扎流程(自定义按钮移动、群响应。)
    将FAT磁盘转化为NTFS格式。
    VC监视新硬件插入电脑。
    VC读取分析网络文件
    工序打扎流程(箭头实现、刷新画面)
    VC实现自定义按钮响应拖动
    VC中ListCtrl经验总结【转载】
    C++的优先级
    VC画面闪烁及解决方法
    改变 CListCtrl、CHeaderCtrl 高度、字体、颜色和背景
  • 原文地址:https://www.cnblogs.com/superMay/p/5848476.html
Copyright © 2011-2022 走看看