I'm using Sequel Pro 0.9.9.1 Build 3408.
I want to add a foreign key to a table and also on delete cascade.
I can't find anything in the GUI that allows me to add foreign keys.
Anyone know how to do this?
ALTER TABLE students ADD FOREIGN KEY (student_id) REFERENCES points(id); To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the following SQL syntax: ALTER TABLE students ADD CONSTRAINT fk_student_id FOREIGN KEY (student_id) REFERENCES points(id);
You can either declare your table completely in SQL, and just add it that way. Or you can declare the columns in the table so that it is defined. Then select the table and click on Relations.
You can have signed integers as foreign keys. As N.B. noted on the question, the type and sign of the fields need to match. So if your primary key in the lookup table is UNSIGNED, then the foreign key field must also be UNSIGNED. If the primary key field is SIGNED, then foreign key field must also be signed.
You can either declare your table completely in SQL, and just add it that way.
Or you can declare the columns in the table so that it is defined. Then select the table and click on Relations. Using the + at the end of the screen will allow you to specify a table and column and if you want cascade behaviour on the update/delete.
The image below may help orient you, it's a bit crude but hopefully shows you where to click.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With