mysql - 检查 mysql 不工作(没有错误)

标签 mysql sql constraints

CREATE TABLE batsman
(
  InningId int NOT NULL,
  PlayerId int NOT NULL,
  BatsmanOrder int(2) NOT NULL,
  BatScore int NOT NULL default 0,
  Balls int NOT NULL default 0,
  sixes int NOT NULL default 0,
  fours int NOT NULL default 0,
  `out` varchar(10) NOT NULL, /*Foreign*/
  catcher int, /*Foreign*/
  bowler int, /*Foreign*/
  Primary Key(InningId, PlayerId),
  Foreign Key (PlayerId) references player(Id),
  Foreign Key (InningId) references inning(Id),
  CHECK (`out` in ("Caught", "Run Out", "Not Out", "Bowled", "lbw"))
  ) ENGINE=INNODB;

我正在使用 MySql,但我无法让我的 Check 工作,它似乎根本不起作用,我没有收到错误或任何错误。这可能与 out 周围的 '' 标签有关,因为 out 是一个关键字!

最佳答案

引用12.1.17. CREATE TABLE Syntax MySQL 手册:

The CHECK clause is parsed but ignored by all storage engines

也许这可以解释这一点?


纯粹作为建议,也许您可​​能的解决方案是使用:

  • 10.4.4. The ENUM Type对于您的列,如果它必须只包含几个值 - 请注意该方法有缺点,因为枚举并不完全像 varchar 那样工作。
  • 一个Trigger防止插入无效数据

但这些只是疯狂的提议我没有在这种情况下进行测试

关于mysql - 检查 mysql 不工作(没有错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2358471/

相关文章:

mysql - 使用 solr 和 tomcat6 的数据导入问题(HTTP 状态 404)

mysql - 将 MySQL 字符串日期转换为 Y-m-d H :i:s

sql - 如果元组出现超过预定义的数量(如 5),则返回 sql 查询结果中的元组。

ios - 使用不断变化的约束(进度条)Swift 对 imageView 进行动画处理

unit-testing - Grails 2.1 单元测试命令对象 mockForConstraintsTests 不工作?

PHP super 基础内容管理请指教

php - 如何从一个php文件中创建不同的类别 View

mysql - Windows 8.1安装RMySQL的另一个错误

mysql - 输出自 MySQL 中特定日期范围以来未重复订购的客户

ios - 无法同时满足打开相机的约束