Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a foreign key in SequelPro?

Tags:

sequelpro

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?

like image 315
Padraig Avatar asked Sep 03 '13 02:09

Padraig


People also ask

How do I add a foreign key to an existing keyboard?

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);

How do I create a foreign key in sequel pro?

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.

Can you add a foreign key to an existing table?

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.


1 Answers

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.

enter image description here

like image 109
Stephen O'Flynn Avatar answered Sep 24 '22 02:09

Stephen O'Flynn