5、ERT,UPDATE,DELETEASBEGIN DECLARE@nInsRows INT --用于插入记录条数统计 DECLARE@nCount INT --用于删除记录条数统计 DECLARE@nCOde INT --删除的记录 --统计插入的的记录数并存放在@nInsRows里面 SELECT@nInsRows=COUNT(*) FROMINSERTED --统计删除的记录数并存放在@nCount里面 S
6、ELECT @nCount=COUNT(*) FROM DELETED IF(@nCount>0) BEGIN delete C from deleted where C.id=deleted.id END IF(@nInsRows>0AND@nCount=0) --如果是插入数据 BEGIN insertintoCselect*frominserted END IF(@
7、nInsRows>0AND@nCount>0) --如果是更新数据 BEGIN select@nCOde=idfrominserted IFEXISTS(select*fromCwhereC.id=@nCOde) BEGIN updateCsetC.id='xx'whereid=@nCOde) END ELSE BEGIN insertintoCselect*frominserted END END END 另外,下面的一段文字值得体会: 在MSSQLSer