title: Trigger after insert on not null column
body: <p>I have a table that contains two <code>not null</code> columns <code>Created</code> and <code>Updated</code>.</p>
  
  <p>I wrote corresponding triggers</p>
  
  <pre><code>ALTER TRIGGER [dbo].[tr_category_inserted] ON [dbo].[Category]
  AFTER INSERT
  AS
  BEGIN
    UPDATE Category
    SET Created = GETDATE(), Updated = GETDATE()
    FROM inserted
    WHERE Category.ID = inserted.ID;
  END
  </code></pre>
  
  <p>and</p>
  
  <pre><code>ALTER TRIGGER [dbo].[tr_category_updated] ON [dbo].[Category]
  AFTER UPDATE
  AS
  BEGIN
    UPDATE Category
    SET Updated = GETDATE()
      FROM inserted
          inner join [dbo].[Category] c on c.ID = inserted.ID
  END
  </code></pre>
  
  <p>but if I am inserting a new row I get an error</p>
  
  <blockquote>
    <p>Cannot insert the value NULL into column 'Created', table
    'Category'; column does not allow nulls. INSERT fails.</p>
  </blockquote>
  
  <p>Insert command:</p>
  
  <pre><code>INSERT INTO [Category]([Name], [ShowInMenu], [Deleted])
       VALUES ('category1', 0, 0)
  </code></pre>
  
  <p>How can I write such triggers without a setting to these columns to allow null?</p>