---
title: "Trigger after insert on not null column"  
description: "Trigger after insert on not null column"  
author: "Anonymous User"  
published: 2013-05-04  
updated: 2013-05-04  
canonical: https://www.mindstick.com/forum/807/trigger-after-insert-on-not-null-column  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 1 minute  

---

# Trigger after insert on not null column

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
I have a table that contains two [not null](https://www.mindstick.com/interview/1933/what-is-not-null-constraint) columns Created and Updated.\
I wrote corresponding [triggers](https://www.mindstick.com/articles/337000/what-are-sql-triggers-and-ways-of-using-them-effectively)\
ALTER [TRIGGER](https://www.mindstick.com/blog/167/triggers-in-wpf) [dbo].[tr_category_inserted] ON [dbo].[Category]AFTER INSERTASBEGIN [UPDATE](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) Category SET Created = [GETDATE](https://www.mindstick.com/interview/295/difference-between-getdate-and-sysdatetime)(), Updated = GETDATE() FROM inserted WHERE Category.ID = inserted.ID;ENDand\
ALTER TRIGGER [dbo].[tr_category_updated] ON [dbo].[Category]AFTER UPDATEASBEGIN UPDATE Category SET Updated = GETDATE() FROM inserted [inner join](https://www.mindstick.com/forum/33572/sql-inner-join-keyword) [dbo].[Category] c on c.ID = inserted.IDENDbut if I am inserting a new row I get an error\
Cannot insert the value NULL into column 'Created', table 'Category'; column does not allow nulls. INSERT fails.\
Insert [command](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net):\
INSERT INTO [Category]([Name], [ShowInMenu], [[Deleted](https://www.mindstick.com/forum/160487/how-to-remove-the-deleted-git-code-marker-in-scrollbar-in-visual-studio-2022)]) VALUES ('category1', 0, 0)How can I write such triggers without a setting to these columns to allow null?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Ezra!\
You can try as following\
Possible use INSTEAD OF trigger\
CREATE TRIGGER [dbo].[tr_category_inserted] ON [dbo].[Category]INSTEAD OF INSERTASBEGIN INSERT Category(Name, ShowInMenu, Deleted, Created, Updated) SELECT Name, ShowInMenu, Deleted, GETDATE(), GETDATE() FROM inserted iEND\
I hope it's helpful to you!


---

Original Source: https://www.mindstick.com/forum/807/trigger-after-insert-on-not-null-column

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
