---
title: "SQL trigger, check if certain value was entered"  
description: "SQL trigger, check if certain value was entered"  
author: "Anonymous User"  
published: 2013-04-17  
updated: 2013-04-17  
canonical: https://www.mindstick.com/forum/778/sql-trigger-check-if-certain-value-was-entered  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 2 minutes  

---

# SQL trigger, check if certain value was entered

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances)!\
[INSERT](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) INTO table_name (column1, column2, column3,...)[VALUES](https://www.mindstick.com/forum/327/sum-textbox-values) (value1, value2, value3,...)Now what to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone):\
If inserted value1 = null, change it to 0\
How to do it via [trigger](https://www.mindstick.com/blog/167/triggers-in-wpf)? I googled for examples and I have [never](https://yourviews.mindstick.com/view/290/zoos-prisons-for-beings-who-have-never-committed-a-crime) [ever done](https://answers.mindstick.com/qa/31985/what-is-the-nicest-thing-you-have-ever-done-for-a-complete-stanger-and-vice-versa) a trigger, so it is rather confusing.\
So far got only this:\
CREATE TRIGGER testTriggerON myTableAFTER INSERT, [UPDATE](https://www.mindstick.com/forum/156353/what-is-hummingbird-update), [DELETE](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax)\
[Advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) Thanks!

## Replies

### Reply by AVADHESH PATEL

Hi Jacob!\
You can add default value . This is how it's done for a new column. For existing one you should add constraint. Check Update 2

```
ALTER TABLE table_name ADD column1 int NOT NULL DEFAULT(0)Add column, with default value, to existing table in SQL Server
```

\
**UPDATE:**\
To set default value, you should update NULL values at first.\

```
UPDATE table_name SET column1 = 0WHERE column1 IS NULLUPDATE 2:
```

\
Try adding constraint\

```
ALTER TABLE table_name ADD CONSTRAINT DF_column1 DEFAULT 0 FOR column1 
```

### Reply by AVADHESH PATEL

Hi Jacob!\
You can try another way as following\
You could write this in the trigger:\
UPDATE T SET value1 =0FROM table_name TJOIN INSERTED ION T.<id>=I.<id>WHERE I.value1 is nullINSERTED table which is accessible only within trigger will store the values that have inserted..\


---

Original Source: https://www.mindstick.com/forum/778/sql-trigger-check-if-certain-value-was-entered

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
