I am new to SQL and I started building my own project. I am having issues creating a foreign key on my second table. . Please let me know what I am missing here.
Advertisement
Answer
The second CREATE TABLE statement should be:
CREATE TABLE entry ( issuer_id INT AUTO_INCREMENT PRIMARY KEY, issuer_name VARCHAR(20) NOT NULL, fine INT, book_id INT, due_date DATE, FOREIGN KEY (book_id) REFERENCES book_table (book_id) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (due_date) REFERENCES book_table (due_date) ON DELETE CASCADE ON UPDATE CASCADE );