MySQL和检查约束 [英] MySQL and Check Constraints

查看:99
本文介绍了MySQL和检查约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个使用MySQL并且由PHP前端使用的应用程序。写这个系统的人已经去了一些相当复杂的长度,以确保用户输入的代码是有效的 - 和tat意味着这些代码也存在于另一个表中。

I have inherited an application that uses MySQL and that is used by a PHP front end. The guy that wrote this system has gone to some fairly convoluted lengths to ensure that codes that users enter are valid - and tat means that these codes also exist in another table.

当我第一次看到这里,我想知道为什么他没有使用CHECK约束,让dbms排序 - 我有一个负载的不同的程序实现相同的检查,而不是只有一个地方dbms。然后我发现MySQL不支持Check约束(不严格真实 - 它支持语法,但只是忽略它)。

When I first saw this I wondered why he hadn't used CHECK constraints and let the dbms sort this out - I have visions of a load of different programs implementing the same checks instead of just the one place in the dbms. And then I found out that MySQL doesn't support Check constraints (not strictly true - it supports the syntax but just ignores it).

有一种方法,我可以在MySQL中实现检查约束?

Is there a way that I can implement Check Constraints in MySQL?

任何提示,建议等都是很好的。

Any hints, suggestions etc, would be great.

推荐答案

你可以用触发器实现类似的东西,但MySQL本身不支持CHECK约束。不要担心,它会让你定义它们,只是默默地忽略他们!

You can implement something similar to them with triggers, but MySQL itself doesn't support CHECK constraints. Don't worry though, it'll let you define them and just silently ignore them!

这篇关于MySQL和检查约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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