<small id='F3HLO'></small><noframes id='F3HLO'>

    • <bdo id='F3HLO'></bdo><ul id='F3HLO'></ul>

        <tfoot id='F3HLO'></tfoot>
      1. <legend id='F3HLO'><style id='F3HLO'><dir id='F3HLO'><q id='F3HLO'></q></dir></style></legend>
      2. <i id='F3HLO'><tr id='F3HLO'><dt id='F3HLO'><q id='F3HLO'><span id='F3HLO'><b id='F3HLO'><form id='F3HLO'><ins id='F3HLO'></ins><ul id='F3HLO'></ul><sub id='F3HLO'></sub></form><legend id='F3HLO'></legend><bdo id='F3HLO'><pre id='F3HLO'><center id='F3HLO'></center></pre></bdo></b><th id='F3HLO'></th></span></q></dt></tr></i><div id='F3HLO'><tfoot id='F3HLO'></tfoot><dl id='F3HLO'><fieldset id='F3HLO'></fieldset></dl></div>
      3. MySQL 触发器可以模拟 CHECK 约束吗?

        Can a MySQL trigger simulate a CHECK constraint?(MySQL 触发器可以模拟 CHECK 约束吗?)

            1. <legend id='RbmCT'><style id='RbmCT'><dir id='RbmCT'><q id='RbmCT'></q></dir></style></legend>
                <tbody id='RbmCT'></tbody>
                • <bdo id='RbmCT'></bdo><ul id='RbmCT'></ul>
                  <tfoot id='RbmCT'></tfoot>

                  <i id='RbmCT'><tr id='RbmCT'><dt id='RbmCT'><q id='RbmCT'><span id='RbmCT'><b id='RbmCT'><form id='RbmCT'><ins id='RbmCT'></ins><ul id='RbmCT'></ul><sub id='RbmCT'></sub></form><legend id='RbmCT'></legend><bdo id='RbmCT'><pre id='RbmCT'><center id='RbmCT'></center></pre></bdo></b><th id='RbmCT'></th></span></q></dt></tr></i><div id='RbmCT'><tfoot id='RbmCT'></tfoot><dl id='RbmCT'><fieldset id='RbmCT'></fieldset></dl></div>

                  <small id='RbmCT'></small><noframes id='RbmCT'>

                  本文介绍了MySQL 触发器可以模拟 CHECK 约束吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想在 MySQL 中使用 CHECK 约束,但它不受支持.(与其他 RDBMS 不同,它会理解但不强制执行 CHECK.)

                  I want to use the CHECK constraint in MySQL, but it is not supported. (Unlike other RDBMS, it will understand but not enforce the CHECKs.)

                  我已经看到了一些使用触发器的解决方法.但他们倾向于为相关字段设置默认值,而不是返回错误.

                  I have seen some workarounds with triggers. But they tend to set a default value to the field in question instead of returning an error.

                  是否可以构造一个触发器,在不满足条件时返回错误?

                  Is it possible to construct a trigger that returns an error if a condition is not met?

                  最终我想要一个复制 CHECK 约束的触发器.

                  Ultimately I want a trigger that copies a CHECK constraint.

                  推荐答案

                  试试下面的语法

                  CREATE TRIGGER mytabletriggerexample
                  BEFORE INSERT
                  FOR EACH ROW BEGIN
                  IF(NEW.important_value) < (fancy * dancy * calculation) THEN
                      DECLARE dummy INT;
                  
                      SELECT Your meaningful error message goes here INTO dummy 
                          FROM mytable
                        WHERE mytable.id=new.id
                  END IF; END;
                  

                  这篇关于MySQL 触发器可以模拟 CHECK 约束吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
                  MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
                  Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
                  How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
                  Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
                  Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)

                  <small id='PLNW8'></small><noframes id='PLNW8'>

                      <bdo id='PLNW8'></bdo><ul id='PLNW8'></ul>

                        <tbody id='PLNW8'></tbody>
                          <legend id='PLNW8'><style id='PLNW8'><dir id='PLNW8'><q id='PLNW8'></q></dir></style></legend>
                        1. <i id='PLNW8'><tr id='PLNW8'><dt id='PLNW8'><q id='PLNW8'><span id='PLNW8'><b id='PLNW8'><form id='PLNW8'><ins id='PLNW8'></ins><ul id='PLNW8'></ul><sub id='PLNW8'></sub></form><legend id='PLNW8'></legend><bdo id='PLNW8'><pre id='PLNW8'><center id='PLNW8'></center></pre></bdo></b><th id='PLNW8'></th></span></q></dt></tr></i><div id='PLNW8'><tfoot id='PLNW8'></tfoot><dl id='PLNW8'><fieldset id='PLNW8'></fieldset></dl></div>

                            <tfoot id='PLNW8'></tfoot>