将来自不同表的 PK 匹配到 SQL 服务器中的复合 PK FK

Matching PK from different tables to a composite PK FK in SQL Server

图像反映了预期的结果。我正在尝试定义 product_translation Table 复合主键与 Tables product[=25 中的 PK 之间的关系=] 和 语言 使用 Microsoft SQL Server 2016 Management Studio。当我尝试定义 product_translation 复合 PK 和产品 PK 之间的关系时,出现错误:

Both sides of a relationships must have same number of columns

这是有道理的,但向导不允许我从两个不同的表中选择匹配复合 PK 所需的两个 PK,这是目前的情况。

由于所有三个表都已设置,是否有 ALTER 语句允许我设置所需的关系?

只需删除table product_translation..请先确保您没有任何数据在那里。然后添加如下代码。

创建 TABLE [product_translation] ( 主键聚集(product_non_transid,language_id), FOREIGN KEY ( product_non_transid) 参考 [Product] ( Id ) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY ( language_id) 参考 [language] ( Id ) ON UPDATE NO ACTION ON DELETE CASCADE, product_name Varchar2(100), 说明 Varchar2(500) )