开发者

Dynamic to create trigger to do insert, update and delete operation in sql server 2008?

开发者 https://www.devze.com 2023-03-30 05:41 出处:网络
i have 100 tables in my database. The tables are Product Warehouse inventoty ... etc I want to write the trigger, for which table i want.

i have 100 tables in my database.

The tables are

Product 
Warehouse
inventoty

... etc

I want to write the trigger, for which table i want.

For example :

Product table i made any changes like update, delete or insert that changes stored into

Product_Log table.

Eg:

Product table

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

Product_Log table

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

If i made any changes in Product table it automatic insert into Product_Log table.

Update Product set Productname = 'vat' where ProductId='M1'

Product table

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

Product_Log table

 ProductId   ProductName  Price  
   M1         Tank           100
   M2         water          722
   M3         Lift           342
   M1         开发者_JS百科Vat            1234

If i delete or update the row from Product that row also insert into Product_Log table.


Have a look at the sys.tables and sys.columns catalog views which provide you with the information about tables and their columns.

From this information you can write TSQL code to generate your insert/update/delete triggers.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号