SQL Server 2012引用表中的列无效

时间:2016-11-20 20:14:25

标签: sql-server foreign-keys create-table

我正在尝试在数据库中创建这3个表:

CREATE TABLE MEETS(
Date            date,
Opponent        char(100),
Result          char(100),
JUScore         int,
OpponentScore   int
CONSTRAINT      MEET_PK PRIMARY KEY(Date, Opponent)

);

CREATE TABLE ROSTER(
PlayerID        int         PRIMARY KEY NOT NULL,
PlayerLastName  char(100),
PlayerFirstName char(100),
Position        char(100),
Hometown        char(100),
HighSchool      char(100),
Class           char(100)

);

CREATE TABLE PLAYERS(
Date            date        FOREIGN KEY REFERENCES MEETS(MEET_PK),
Opponent        char(100)   FOREIGN KEY REFERENCES MEETS(MEET_PK),
PlayerName      char(100),
CONSTRAINT      PLAYER_PK   PRIMARY KEY(Date, Opponent)

);

前两张表创建得很好,但是我在PLAYERS表中收到错误说:外键' FK__PLAYERS__Date__52593CB8'引用无效列' MEET_PK'参考表格' MEETS'。 MEETS表中的列似乎已经存在,所以我不确定如何编写它以便正确显示。约束不算作列吗?如果是这样,写它的另一种方式是什么?

0 个答案:

没有答案