title: Store any transaction in log table SQL Server
body: <p>I have lots of tables in my SQL Server database. When any action happens, like an <code>Insert</code>, <code>Update</code>, <code>Delete</code>, I want to store the data in a <code>Log</code> table as shown here:</p>
  <p><code>Product</code> table:</p>
  <pre><code>| ID  | Name    | Other |
  | --- | ------- | ---   |
  | 1   | Book    | ...   |
  | 2   | Bicycle | ...   |
  </code></pre>
  <p>If any Insert, Update or Delete happens, I want to have something like this:</p>
  <p><code>Log</code> table:</p>
  <pre><code>| ID  | RowId   | TableName  | Action |
  | --- | ------- | ---------- | ------ |
  | 1   | 1       | Product    | Insert |
  | 2   | 2       | Product    | Insert |
  | 3   | 15      | Category   | Update |
  | 4   | 60      | Customer   | Insert |
  </code></pre>
  <p>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).</p>
  <p>For a single table a <a href="https://www.aspsnippets.com/Articles/SQL-Server-Insert-data-to-another-Table-using-Insert-Update-and-Delete-Triggers.aspx" rel="nofollow noreferrer">trigger</a> is a good idea and it works fine, but what about all tables? As the example shows, <code>Category</code> and <code>Customer</code> tables are other tables in my database.</p>