我有一个简单的架构:
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
表定义:
CREATE TABLE technologySynonyms (
synonymId INT PRIMARY KEY AUTO_INCREMENT,
sourceTechnologyName VARCHAR(50) UNIQUE,
targetTechnologyName VARCHAR(50) REFERENCES technologies(technologyName)
);
我没有错误 - 查询执行正常并且创建了表,但是当我插入一个验证外键约束的记录时:
INSSERT INTO technologySynonyms (sourceTechnologyName, targetTechnologyName)
VALUES ('JS', 'Value not present in technologies table!!');
插入记录。
这给我留下了几个问题:
答案 0 :(得分:2)