我收到此错误:
引用表 'Reviewers' 中没有与外键 'FK_Review_Review_ID' 中的引用列列表匹配的主键或候选键。
消息 1750,级别 16,状态 0,行 57
无法创建约束或索引。请参阅以前的错误。
我的代码:
/* Table Creation Products */
CREATE TABLE Products
(
Product_Name VARCHAR(120) NOT NULL
,Product_URL VARCHAR(165) NOT NULL
,Price MONEY CHECK (Price > 0) NOT NULL
)
GO
/* Entity Integrity by Primary Key*/
ALTER TABLE Products
ADD CONSTRAINT PK_Products_Product_URL
PRIMARY KEY (Product_URL)
GO
/* Table Creation Reviewers */
CREATE TABLE Reviewers
(
Reviewer_ID INT NOT NULL
,Review_ID INT NOT NULL
,Review_Summary VARCHAR(15) NOT NULL
,Review VARCHAR(280) NOT NULL
,Review_Date DATE
,Overall_Rating INT NOT NULL
,Helpful INT
,Unhelpful INT
)
GO
ALTER TABLE Reviewers
ADD CONSTRAINT PK_Reviewers_Reviewer_ID_Review_ID
PRIMARY KEY (Reviewer_ID, Review_ID)
GO
/* Table Creation Review */
CREATE TABLE Review
(
Product_URL VARCHAR(165) NOT NULL
,Review_ID INT NOT NULL
)
GO
/* Entity Integrity by Primary Key*/
ALTER TABLE Review
ADD CONSTRAINT PK_Product_URL_Review_ID
PRIMARY KEY (Product_URL, Review_ID)
GO
/* Entity Integrity by Foreign Key */
ALTER TABLE Review
ADD CONSTRAINT FK_Review_Product_URL
FOREIGN KEY (Product_URL)
REFERENCES Products (Product_URL)
GO
ALTER TABLE Review
ADD CONSTRAINT FK_Review_Review_ID
FOREIGN KEY (Review_ID)
REFERENCES Reviewers (Review_ID)
GO