link 这两个表的最佳方法是什么

What would be the best way to link these two tables

我在数据库中有两个 table,它们都来自官方政府参考 table,最初以电子表格形式提供。

这两个table的结构如下图所示。

Table 1(物种代码)

Table 2(允许的表示代码)

当我尝试在第一个和第二个之间创建关系时(以便充分利用在第二个中查找值的能力 table 我在尝试 link speciescodes.FAOCode 到 allowedstates.ErsSpeciesCodes).

'SpeciesCodeLookup'table保存成功 'AllowedPresentationAndStateCodesLookup' table - 无法创建关系 'FK_AllowedPresentationAndStateCodesLookup_SpeciesCodeLookup'。
ALTER TABLE 语句与 FOREIGN KEY 约束 "FK_AllowedPresentationAndStateCodesLookup_SpeciesCodeLookup" 冲突。冲突发生在数据库 "FishTrackerPro"、table "dbo.SpeciesCodeLookup"、列 'FAOCode'。

谁能赐教 1)为什么会出现这个错误 2) 有没有办法(通过改变一个或另一个 table 可以建立这种关系?

您遇到这个问题似乎是因为不符合参照完整性。即外键 table 不能有主键 table 中不存在的值。

检查这些链接:

  1. Alter table conflicted with foreign key constraint
  2. SQL conflicted with the FOREIGN KEY constraint