Foreign key constraints:
isbn references the ISBN in the Books table
id references the member ID in the Members table
Here is the CREATE TABLE statement for the Lending table:
SQL
CREATE TABLE Lending (
isbn INT,
id INT,
checkout DATETIME,
returned DATETIME,
PRIMARY KEY (isbn, id, checkout),
FOREIGN KEY (isbn) REFERENCES Books(isbn),
FOREIGN KEY (id) REFERENCES Members(id)
);
This statement defines the following:
Table name: Lending
Columns:
isbn (INT): references the book being loaned (foreign key)
id (INT): references the member borrowing the book (foreign key)
checkout (DATETIME): timestamp when the book was checked out
returned (DATETIME): timestamp when the book was returned (nullable)
Primary key: (isbn, id, checkout) - ensures unique combinations of book, member, and checkout time
Foreign key constraints:
isbn references the ISBN in the Books table
id references the member ID in the Members table
This structure allows us to track borrowings, identify overdue books, and calculate statistics on member borrowing patterns.