内联

时间:2015-05-05 08:28:57

标签: mysql 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表定义:

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!!');

插入记录。

这给我留下了几个问题:

  1. 我的SQL出了什么问题?这不行吗?
  2. 我可以使MySQL Workbench更严格吗?如果查询被立即拒绝,我会更喜欢它。