In SQL Server, I got this error:
There are no primary or candidate keys in the referenced table 'BookTitle' that match the referencing column list in the foreign key 'FK__BookCopy__Title__2F10007B'.
I first created a relation called the BookTitle
relation.
CREATE TABLE BookTitle (
ISBN CHAR(17) NOT NULL,
Title VARCHAR(100) NOT NULL,
Author_Name VARCHAR(30) NOT NULL,
Publisher VARCHAR(30) NOT NULL,
Genre VARCHAR(20) NOT NULL,
Language CHAR(3) NOT NULL,
PRIMARY KEY (ISBN, Title))
Then I created a relation called the BookCopy
relation. This relation needs to reference to the BookTitle
relation's primary key, Title
.
CREATE TABLE BookCopy (
CopyNumber CHAR(10) NOT NULL,
Title VARCHAR(100) NOT NULL,
Date_Purchased DATE NOT NULL,
Amount DECIMAL(5, 2) NOT NULL,
PRIMARY KEY (CopyNumber),
FOREIGN KEY (Title) REFERENCES BookTitle(Title))
But I can't create the BookCopy
relation because the error stated above appeared.