title: How to create trigger for whole database in SQL Server?
body: <p>I have database with 7 tables and every table has these columns:</p>
  <pre><code>created_at SMALLDATETIME NOT NULL DEFAULT GETDATE(),
  updated_at SMALLDATETIME NOT NULL DEFAULT GETDATE()
  </code></pre>
  <p>As you can see, when you insert data into a table, it will have default <code>created_at</code> and <code>updated_at</code> columns.</p>
  <p>As I know, it's impossible in SQL Server create autoupdated columns like in MySQL:</p>
  <pre><code>created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
  </code></pre>
  <p>I need to project my database, so, when record is inserted, <code>updated_at</code> will be updated.</p>
  <p>Of course, I can create just 7 triggers, just like that:</p>
  <pre><code>CREATE TRIGGER E_U_CTD
  ON Cities
  FOR UPDATE
  AS
      UPDATE T
      SET updated_at = SYSDATETIME()
      FROM CitiesTest AS T
      JOIN inserted AS i ON T.id = i.id;
  </code></pre>
  <p>But is there more convenient solution (what if I had 100 tables)?</p>