I have 2 tables one named Students and one named Grades and I'm trying to add a foreign key constraint to the Grades table so that if someone is deleted from the Students table all of their grades will be deleted as well. I have a column named TNumber to match the 2. Here's my code so far.
ALTER TABLE Grades
ADD CONSTRAINT fk_Grades
FOREIGN KEY (TNumber)
REFERENCES Students(TNumber) ON DELETE CASCADE;
The problem is that the code runs but it doesn't create the foreign key. Could someone just look at it and see if I'm doing something wrong in my syntax because the code runs and doesn't throw any errors.
SHOW CREATE TABLE, remember that code is king when asking for help. To create a minimal test case for DB related questions, include statements to create the table(s) and (if asking about DML queries) fill them with sample data (INSERT INTO ...). For a question such as this, where the problem doesn't depend on the data in the tables, you can leave out the statements to fill the tables with sample data.