在MySQL中使用REFERENCES关键字

潘卡·德维维迪(Pankaj Dwivedi)

我在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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在MySQL中使用REFERENCES关键字

来自分类Dev

在DLL中使用默认关键字

来自分类Dev

javascript中使用IIFE的“ this”关键字

来自分类Dev

在JavaScript对象中使用'this'关键字

来自分类Dev

在Python中使用global关键字

来自分类Dev

在AutoHotKey中使用IfWinActive关键字

来自分类Dev

在C ++中使用C关键字

来自分类Dev

在Android中使用超级关键字

来自分类Dev

在Retrolambda中使用'this'关键字

来自分类Dev

在JavaScript对象中使用'this'关键字

来自分类Dev

在JavaScript中使用'this'关键字

来自分类Dev

在方法中使用“self”关键字

来自分类Dev

Mysql IN关键字

来自分类Dev

使用ALL关键字的MySQL查询

来自分类Dev

在 Rebol 中使用关键字与在红色中使用关键字

来自分类Dev

如何在mysql中使用in关键字时获得有序结果集

来自分类Dev

在CONCAT函数中使用NEW关键字插入时,MYSQL触发错误

来自分类Dev

如何在mysql codeigniter php中使用select来计算匹配的关键字?

来自分类Dev

如何在PHP和MySQL中使用关键字正确搜索

来自分类Dev

为什么在 UPDATE SET 中使用 AND 关键字时 MySQL 不会抛出错误

来自分类Dev

在Dapper中使用Async Await关键字

来自分类Dev

在Ruby块中使用return关键字

来自分类Dev

如何在Scala中使用“元组”关键字?

来自分类Dev

在F#中使用关键字作为成员名称

来自分类Dev

为什么要在Java中使用`transient`关键字?

来自分类Dev

Cython-在for循环中使用“ from”关键字

来自分类Dev

在C#中使用`dynamic`关键字无法编译

来自分类Dev

在类中使用关键字this与多个构造函数

来自分类Dev

在peewee中使用python关键字作为模型字段