---
title: "Blocking blank value entry into a database"  
description: "Blocking blank value entry into a database"  
author: "Anonymous User"  
published: 2013-05-02  
updated: 2013-05-02  
canonical: https://www.mindstick.com/forum/787/blocking-blank-value-entry-into-a-database  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 2 minutes  

---

# Blocking blank value entry into a database

Hi Everyone!\
I have a [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) into which i enter values through an application. To be specific ,i enter [certain value](https://www.mindstick.com/forum/23089/in-java-how-can-i-test-if-an-array-contains-a-certain-value) in a text-box and click on save [Button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) which handles the task of saving it into the database. The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) that i'm facing is even when i don't enter any value in the text-box and click on save button the value gets saved into the database( A case which i should have handled in the code ). Now i want to write a SQL-[script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) so that it blocks the entry of the blank values into the database .\
for example lets say ..books be the table which contains columns author_name , price , year\
so if a try to enter a blank author name and try saving it, it should not be saved\
I tried this:\
DELIMITER |\
CREATE [TRIGGER](https://www.mindstick.com/blog/167/triggers-in-wpf) test AFTER [INSERT](https://www.mindstick.com/blog/173/executing-insert-delete-or-update-query-in-sqlserver-using-ado-dot-net) ON books FOR EACH ROW BEGIN IF NEW.author_name= '' THEN delete from books where author_name= ''; END IF; END;|booksDELIMITER ;can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) how to do this , is there any other method to achieve this ?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Jayprakash!\
\
Your trigger should look something like this:\
\
CREATE TRIGGER <name of the trigger> BEFORE INSERT ON <name of table>\
FOR EACH ROW BEGIN\
IF NEW.<fieldname> = ''\
THEN\
SET NEW='Error: Cannot insert record empty value for <fieldname>';\
END IF;\
END\
;\
Create the trigger BEFORE insert\
\
OR \
\
You should validate user input in the application.


---

Original Source: https://www.mindstick.com/forum/787/blocking-blank-value-entry-into-a-database

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
