CREATE TABLE titlexplan(
id INTEGER NOT NULL,
title_id INTEGER NOT NULL ,
plan_id INTEGER NOT NULL ,
start_date DATETIME NOT NULL,
end_date DATETIME
CHECK (start_date < end_date),
PRIMARY KEY(id),
INDEX (title_id),
FOREIGN KEY (title_id)
REFERENCES title(id)
INDEX (plan_id),
FOREIGN KEY (plan_id)
REFERENCES plan(id)
);
This is the code I am using, and I am getting a syntax error: #1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INDEX (plan_id), FOREIGN KEY (plan_id) REFERENCES plan(id) )' at line 10.
I am trying to get the title_id and plan_id to update when the respective id’s from other tables update, and I’m trying to track changes.
I haven’t been able to find a clear guide for how to do this, and these queries work in part but not in whole. I don’t think that I need a primary key in this table, but I get a warning: “Warning, table contains no primary key,” when I don’t use primary keys. So, I just added the ‘id’ column. I’m not thinking it’s actually needed, though.
Please advise.
Thank you.
I beleive this should work. “ON UPDATE CASCADE” will cause these foreign keys to update any time the key they are referencing updates.
Also make sure your using innoDB engine for the foreign keys to work properly.
If you didn’t want the id column and the combination of title_id and plan_id was always unique you could do