内联描述时外键约束无效
Foreign key constraint has no effect when described inline
我有一个简单的模式:
CREATE TABLE technologies (
technologyName VARCHAR(50) NOT NULL PRIMARY KEY
);
CREATE TABLE technologySynonyms (
synonymId INT PRIMARY KEY AUTO_INCREMENT,
sourceTechnologyName VARCHAR(50) UNIQUE,
targetTechnologyName VARCHAR(50),
FOREIGN KEY (targetTechnologyName)
REFERENCES technologies(technologyName)
);
我想进一步简化 technologySynonyms
table 定义:
CREATE TABLE technologySynonyms (
synonymId INT PRIMARY KEY AUTO_INCREMENT,
sourceTechnologyName VARCHAR(50) UNIQUE,
targetTechnologyName VARCHAR(50) REFERENCES technologies(technologyName)
);
我没有收到任何错误 - 查询执行正常并创建了 table,但是当我插入一条验证外键约束的记录时:
INSSERT INTO technologySynonyms (sourceTechnologyName, targetTechnologyName)
VALUES ('JS', 'Value not present in technologies table!!');
记录已插入。
这给我留下了几个问题:
- 我的 SQL 怎么了?这应该行不通吗?
- 我可以让 MySQL Workbench 更严格吗?如果查询立即被拒绝,我会更喜欢它。
我有一个简单的模式:
CREATE TABLE technologies (
technologyName VARCHAR(50) NOT NULL PRIMARY KEY
);
CREATE TABLE technologySynonyms (
synonymId INT PRIMARY KEY AUTO_INCREMENT,
sourceTechnologyName VARCHAR(50) UNIQUE,
targetTechnologyName VARCHAR(50),
FOREIGN KEY (targetTechnologyName)
REFERENCES technologies(technologyName)
);
我想进一步简化 technologySynonyms
table 定义:
CREATE TABLE technologySynonyms (
synonymId INT PRIMARY KEY AUTO_INCREMENT,
sourceTechnologyName VARCHAR(50) UNIQUE,
targetTechnologyName VARCHAR(50) REFERENCES technologies(technologyName)
);
我没有收到任何错误 - 查询执行正常并创建了 table,但是当我插入一条验证外键约束的记录时:
INSSERT INTO technologySynonyms (sourceTechnologyName, targetTechnologyName)
VALUES ('JS', 'Value not present in technologies table!!');
记录已插入。
这给我留下了几个问题:
- 我的 SQL 怎么了?这应该行不通吗?
- 我可以让 MySQL Workbench 更严格吗?如果查询立即被拒绝,我会更喜欢它。