Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I am trying to do the sql validation for one of my table field name.

for instance,

my sample table below,
id  productname  stock

1   test               10

2   testing            20

I want to validate, when the stock value comes in below 1 using select query or any other possible ways.

This is what I want.

So please guide me a solution for that.

Thanks in advance..
Posted
Updated 29-Nov-15 23:57pm
v2
Comments
CHill60 30-Nov-15 5:58am    
What have you tried?
What do you mean by "when the stock value comes in"? How are you entering the data?
Have you heard of Check Constraints[^]

1 solution

You can add a constraint to that field by altering the table and check Stock>0

So when ever the stock is less than 1 it will throw error.

SQL
ALTER TABLE Product
ADD CHECK (stock>0)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900