我在MySQL中具有以下表定义。它表示表许可证和许可证服务器之间的M:N关系。
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)
);
这是关键字REFERENCES的正确用法吗?如果将表定义更改为下面的表定义,列的行为是否会有所不同?
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仅在REFERENCES
子句成为FOREIGN KEY
规范的一部分时才对其进行处理。这是手册中的报价:
MySQL解析但忽略“内联
REFERENCES
规范”(在SQL标准中定义),其中引用被定义为列规范的一部分。MySQLREFERENCES
仅在作为单独FOREIGN KEY
规范的一部分指定时才接受子句。
因此,第一个版本将不强制执行外键关系,第二个版本将(假定您正在使用InnoDB
存储引擎)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句