动态创建触发器在sql server 2008中执行插入,更新和删除操作?

时间:2011-08-22 05:55:23

标签: sql sql-server-2008

我的数据库中有100个表。

表格是

Product 
Warehouse
inventoty

...等

我想写一个触发器,我想要哪个表。

例如:

产品表我做了任何更改,例如更新,删除或插入存储在

中的更改

Product_Log table。

例如:

产品表

 ProductId   ProductName  Price
   M1         Tank           100
   M2         water          722
   M3         Lift           342

Product_Log表

 ProductId   ProductName  Price  
   M1         Tank           100
   M2         water          722
   M3         Lift           342

如果我在Product表中进行了任何更改,它会自动插入到Product_Log表中。

更新产品集Productname ='vat',其中ProductId ='M1'

产品表

  ProductId   ProductName  Price
   M1         VAT           100
   M2         water          722
   M3         Lift           342

Product_Log表

 ProductId   ProductName  Price  
   M1         Tank           100
   M2         water          722
   M3         Lift           342
   M1         Vat            1234

如果我从Product中删除或更新该行,该行也会插入到Product_Log表中。

1 个答案:

答案 0 :(得分:0)

查看sys.tablessys.columns目录视图,它们为您提供有关表及其列的信息。

根据此信息,您可以编写TSQL代码以生成插入/更新/删除触发器。