将最大值设置为一列 [英] set maximum value to a column
本文介绍了将最大值设置为一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张表,其中有一个称为age的列(整数类型).该列的最大值应为50.如果超过该最大值,则不应更新该行.
I have a table with a column (int type) called age. This column should hold maximun value 50. If it exceeds then it shouldn't update that row.
表示此列的保留值介于0到50之间.
Means this column shold take values from 0 to 50.
如果我尝试将其更新为51,那应该是不允许的.
If I try to update that to 51 then that shouldn't allow.
任何人都可以帮忙....!
Could any one help....!
推荐答案
尝试一下:
CREATE TRIGGER check_trigger
BEFORE INSERT
ON table
FOR EACH ROW
BEGIN
IF NEW.age<0 OR NEW.age>50 THEN
CALL `Error: Wrong values for age`; -- this trick will throw an error
END IF;
END
这篇关于将最大值设置为一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文