Skip to content
Advertisement

Foreign Key on MySQL

I am new to SQL and I started building my own project. I am having issues creating a foreign key on my second table. code screenshot. 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
    );
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement