如何使用sql验证表字段值? [英] how to validate table field value using sql?
本文介绍了如何使用sql验证表字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试对我的一个表字段名进行sql验证。
例如
,
我的下面的样本表,
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
我想验证,当股票价值低于1时使用选择查询或者任何其他可能的方式。
这就是我想要的。
所以请指导我一个解决方案为此。
在此先感谢..
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..
推荐答案
您可以通过以下方式为该字段添加约束改变表格并检查股票> 0
因此当股票小于1时,它将抛出错误。
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.
ALTER TABLE Product
ADD CHECK (stock>0)
这篇关于如何使用sql验证表字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文