无法将运动 CHAR(6) 引用到其他列错误

cant reference sport CHAR(6) to other column error

正如标题所说,出于某种原因,当我什至没有引用它时,它给了我运动变量不能引用另一列的错误,这是什么原因?

CREATE TABLE club_rates
(club_id NUMBER(4)
CONSTRAINT rates_club_fk REFERENCES club_subscriptiontypes(club_id,subscriptiontype)
,sport CHAR(6)
,subscriptiontype CHAR(11)
,subscription_startdate DATE
,subscription_rate_existing NUMBER(2)
,subscription_rate_new NUMBER(2)
,subscription_enddate DATE
,registration_startdate DATE
,registration_enddate DATE,
CONSTRAINT rates_clubsportsub_pk PRIMARY KEY (club_id, sport, subscriptiontype, subscription_startdate)
);

假设您有 table:

CREATE TABLE club_subscriptiontypes(
  club_id          NUMBER(4),
  subscriptiontype CHAR(11),
  PRIMARY KEY (club_id,subscriptiontype)
);

那么您不想针对单个列内联声明复合主键列,否则您会收到错误消息:

ORA-02256: number of referencing columns must match referenced columns

相反,在语句末尾将其声明为外联:

CREATE TABLE club_rates(
  club_id                    NUMBER(4)
, sport                      CHAR(6)
, subscriptiontype           CHAR(11)
, subscription_startdate     DATE
, subscription_rate_existing NUMBER(2)
, subscription_rate_new      NUMBER(2)
, subscription_enddate       DATE
, registration_startdate     DATE
, registration_enddate       DATE
, CONSTRAINT rates_club_fk
    FOREIGN KEY (club_id, subscriptiontype)
    REFERENCES club_subscriptiontypes(club_id,subscriptiontype)
, CONSTRAINT rates_clubsportsub_pk
    PRIMARY KEY (club_id, sport, subscriptiontype, subscription_startdate)
);

顺便说一句,您可能不想使用固定长度的 CHAR 字符串,而是想要可变长度的 VARCHAR2 字符串。

db<>fiddle here