在MySQL中使用REFERENCES关键字
我在MySQL中有下面的表定义。它表示表许可证和许可证服务器之间的M:N关系在MySQL中使用REFERENCES关键字,mysql,reference,foreign-keys,many-to-many,foreign-key-relationship,Mysql,Reference,Foreign Keys,Many To Many,Foreign Key Relationship,我在MySQL中有下面的表定义。它表示表许可证和许可证服务器之间的M:N关系 create table if not exists served_license ( served_license_id smallint not null, version varchar(16) not null, quantity smallint no
create table if not exists served_license
(
served_license_id smallint not null,
version varchar(16) not null,
quantity smallint not null,
expiry_date char(16) not null,
license_server_id tinyint not null references license_server(license_server_id),
license_id varchar(64) not null references license(feature, product),
primary key (served_license_id)
);
这是关键字引用的正确用法吗?如果我将表定义更改为下面的定义,列的行为会有所不同吗
create table if not exists served_license
(
served_license_id smallint not null,
version varchar(16) not null,
quantity smallint not null,
expiry_date char(16) not null,
license_server_id tinyint not null,
license_id varchar(64) not null,
primary key (served_license_id),
foreign key (license_server_id) references license_server(license_server_id),
foreign key (license_id) references license(feature, product)
);
MySQL只处理
引用
子句,如果它们是外键
规范的一部分。以下是该网站的报价:
MySQL解析但忽略“内联引用
规范”(如SQL标准中所定义),其中引用被定义为列规范的一部分。MySQL仅在指定为单独的外键
规范的一部分时才接受引用
子句
因此,第一个版本不会强制执行外键关系,第二个版本将强制执行(假设您使用的是
InnoDB
存储引擎)。非常感谢您的澄清。