列将如何接受 MySQL 中的有限值 [英] How the Column will Accepts Limited Values in MySQL

查看:41
本文介绍了列将如何接受 MySQL 中的有限值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MySQL Server 5.6.14.0,但无法找到此类约束,使我们能够在列或字段中插入有限的值.例如,我想在一个列中声明一个约束,它只接受从 0 到 10 或 A 到 Z 的值,不超过这个值.

I'm working on MySQL Server 5.6.14.0, And Unable to find such kind of constraint which enable us to insert a limited values in a column or field. For Example, I want to declare a constraint in a columns which accepts only Value from 0 to 10 or A to Z, not more than that.

推荐答案

您可以创建插入/更新触发器,它会检查插入的值并抛出错误,这里是抛出错误的示例:如何在 MySQL 函数中引发错误

You can create insert/update trigger, which will check values inserted and throw error, here is example of throwing error: How to raise an error within a MySQL function

这篇关于列将如何接受 MySQL 中的有限值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆