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/