G
Ghaaroth
I'm making a simple DB to track books that are checked out. I build my
tables in the following order:
CREATE TABLE Publisher(
PublisherID AUTOINCREMENT,
Name Char(255) Not Null,
CONSTRAINT PubPK PRIMARY KEY (PublisherID)
);
CREATE TABLE Author(
AuthorID AUTOINCREMENT,
Name Char(255) Not Null,
CONSTRAINT AuthPK PRIMARY KEY (AuthorID)
);
CREATE TABLE Student(
StudentID AUTOINCREMENT,
Name Char(255) Not Null,
Email Char(255) Not Null,
CONSTRAINT StdPK PRIMARY KEY (StudentID)
);
CREATE TABLE Book(
BookID AUTOINCREMENT,
AuthorID Integer Unique Not Null,
PublisherID Integer Unique Not Null,
Name Char(255) Not Null,
ISBN Char(13),
Total_Count Integer Not Null,
Current_Count Integer Not Null,
CONSTRAINT BookPK PRIMARY KEY (BookID, AuthorID, PublisherID),
CONSTRAINT AuthFK FOREIGN KEY (AuthorID) REFERENCES Author (AuthorID),
CONSTRAINT PubFK FOREIGN KEY (PublisherID) REFERENCES Publisher
(PublisherID)
);
CREATE TABLE Transactions(
TransID AUTOINCREMENT,
BookID Integer Unique Not Null,
StudentID Integer Unique Not Null,
Lend_Dt DATE Not Null,
Return_Dt DATE,
CONSTRAINT TransPK PRIMARY KEY (TransID, BookID, StudentID),
CONSTRAINT BookFK FOREIGN KEY (BookID) REFERENCES Book (BookID),
CONSTRAINT StdFK FOREIGN KEY (StudentID) REFERENCES Student (StudentID)
);
Everything works great until I get to my Transactions table. I've
identified the troublesome line as:
CONSTRAINT BookFK FOREIGN KEY (BookID) REFERENCES Book (BookID),
but I really don't know what I'm messing up. Help anyone?
-G
tables in the following order:
CREATE TABLE Publisher(
PublisherID AUTOINCREMENT,
Name Char(255) Not Null,
CONSTRAINT PubPK PRIMARY KEY (PublisherID)
);
CREATE TABLE Author(
AuthorID AUTOINCREMENT,
Name Char(255) Not Null,
CONSTRAINT AuthPK PRIMARY KEY (AuthorID)
);
CREATE TABLE Student(
StudentID AUTOINCREMENT,
Name Char(255) Not Null,
Email Char(255) Not Null,
CONSTRAINT StdPK PRIMARY KEY (StudentID)
);
CREATE TABLE Book(
BookID AUTOINCREMENT,
AuthorID Integer Unique Not Null,
PublisherID Integer Unique Not Null,
Name Char(255) Not Null,
ISBN Char(13),
Total_Count Integer Not Null,
Current_Count Integer Not Null,
CONSTRAINT BookPK PRIMARY KEY (BookID, AuthorID, PublisherID),
CONSTRAINT AuthFK FOREIGN KEY (AuthorID) REFERENCES Author (AuthorID),
CONSTRAINT PubFK FOREIGN KEY (PublisherID) REFERENCES Publisher
(PublisherID)
);
CREATE TABLE Transactions(
TransID AUTOINCREMENT,
BookID Integer Unique Not Null,
StudentID Integer Unique Not Null,
Lend_Dt DATE Not Null,
Return_Dt DATE,
CONSTRAINT TransPK PRIMARY KEY (TransID, BookID, StudentID),
CONSTRAINT BookFK FOREIGN KEY (BookID) REFERENCES Book (BookID),
CONSTRAINT StdFK FOREIGN KEY (StudentID) REFERENCES Student (StudentID)
);
Everything works great until I get to my Transactions table. I've
identified the troublesome line as:
CONSTRAINT BookFK FOREIGN KEY (BookID) REFERENCES Book (BookID),
but I really don't know what I'm messing up. Help anyone?
-G