Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 外键:列数不等于引用的列数_Sql_Oracle - Fatal编程技术网

Sql 外键:列数不等于引用的列数

Sql 外键:列数不等于引用的列数,sql,oracle,Sql,Oracle,我从oracle收到一个错误,它说“引用列的数量必须与引用列的数量匹配。” 我希望我的列记录在表测量中,以参考记录在表样本 在示例表中的上记录的列必须与科学家数量一起成为复合键的一部分 错误来自 外键(记录在案)参考样本(科学家、记录在案、站点ID) 列上的科学家编号和记录编号必须同时位于复合键中。 如果您能回答我的问题并解释问题所在,我们将不胜感激。您可以在示例表中创建虚拟列: Recorded_virtual varchar2(5) [GENERATED ALWAYS] AS (Scien

我从oracle收到一个错误,它说“引用列的数量必须与引用列的数量匹配。”
我希望我的列记录在测量中,以参考记录在样本
示例表中的上记录的列必须与科学家数量一起成为复合键的一部分
错误来自
外键(记录在案)参考样本(科学家、记录在案、站点ID)

列上的科学家编号和记录编号必须同时位于复合键中。

如果您能回答我的问题并解释问题所在,我们将不胜感激。

您可以在示例表中创建虚拟列:

Recorded_virtual varchar2(5) [GENERATED ALWAYS] AS 
(Scientist||Recorded_On||Site_ID) [VIRTUAL] 
并创建对此列的引用:

CONSTRAINT fk_column
 FOREIGN KEY (Recorded_On)
 REFERENCES Sample(Recorded_virtual )

外键引用需要在数量和类型上与主键匹配。因此,我认为你打算:

CREATE TABLE Measurement (
    Site_ID varchar2(4) not null,
    Scientist_Num varchar2(5) not null,
----^ added for foreign key reference
    Recorded_On date not null,
    Name varchar2(10) not null,
    Value varchar2(10),
    Outlier_Indicator varchar2(10),
    Primary key (Site_ID, Recorded_On, Name),
    FOREIGN KEY (Site_ID) REFERENCES Site(Site_ID),
-------------------------------------^ Presumably you intend the site table
    FOREIGN KEY (Scientist_Num, Recorded_On) REFERENCES 
Sample(Scientist_Num, Recorded_On)
-----------------^ two columns, both need to already be defined
); 

我怀疑您的数据模型还存在其他问题,但这应该可以修复语法错误。如果需要进一步帮助,请询问另一个问题。

错误信息非常清楚。外键列必须与引用表中的键匹配。我不明白引用表中的键应该是什么。我试着让Sample:Recorded_作为引用列,但这不起作用,我也一样。正如我所说,外键引用了一个键。必须具有相同的列数和匹配的数据类型。@Jajimal。你不接受这个答案有什么原因吗?
CREATE TABLE Measurement (
    Site_ID varchar2(4) not null,
    Scientist_Num varchar2(5) not null,
----^ added for foreign key reference
    Recorded_On date not null,
    Name varchar2(10) not null,
    Value varchar2(10),
    Outlier_Indicator varchar2(10),
    Primary key (Site_ID, Recorded_On, Name),
    FOREIGN KEY (Site_ID) REFERENCES Site(Site_ID),
-------------------------------------^ Presumably you intend the site table
    FOREIGN KEY (Scientist_Num, Recorded_On) REFERENCES 
Sample(Scientist_Num, Recorded_On)
-----------------^ two columns, both need to already be defined
);