'Store any transaction in log table SQL Server
I have lots of tables in my SQL Server database. When any action happens, like an Insert, Update, Delete, I want to store the data in a Log table as shown here:
Product table:
| ID | Name | Other |
| --- | ------- | --- |
| 1 | Book | ... |
| 2 | Bicycle | ... |
If any Insert, Update or Delete happens, I want to have something like this:
Log table:
| ID | RowId | TableName | Action |
| --- | ------- | ---------- | ------ |
| 1 | 1 | Product | Insert |
| 2 | 2 | Product | Insert |
| 3 | 15 | Category | Update |
| 4 | 60 | Customer | Insert |
I'm using Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64) Express edition with Advanced Services - some features might not be available for me (reference to documentation).
For a single table a trigger is a good idea and it works fine, but what about all tables? As the example shows, Category and Customer tables are other tables in my database.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
