6

I need to use foreign keys for update and cascade, etc.

ALTER TABLE topics
  ADD FOREIGN KEY(topic_by) REFERENCES users(user_id)
  ON DELETE RESTRICT ON UPDATE CASCADE;

but I am not able to make foreign keys in SQL Buddy.

Any way to do that?

Ike Walker
  • 64,401
  • 14
  • 110
  • 109
  • You did not mention your database name, put your database name prior to your tables name along with a dot (.) – Daniel Morgan Feb 05 '13 at 23:12
  • Though not familiar with sql buddy, I have a comment. Do you get an error message, then please add it to your question. Possibly: wrong table name, wrong column name, autorisation issue (not autorised to alter), no connection to the right db. Or something. – cybork Sep 11 '15 at 22:18
  • 5
    I'm not familiar with SQL Buddy but check your database: Foreign Keys are not supported with **MyISAM**. Please be sure you're using **InnoDB**. See [link](http://dev.mysql.com/doc/refman/5.6/en/storage-engines.html) – zwergmaster Oct 23 '15 at 11:24

2 Answers2

0

did you try this :

ALTER TABLE topics 
ADD CONSTRAINT topic_by FOREIGN KEY(user) 
REFERENCES users(user_id) ON DELETE RESTRICT ON UPDATE CASCADE
0

Try this query:

ALTER TABLE topics
ADD CONSTRAINT topic_by
FOREIGN KEY (user_id) REFERENCES users(user_id);
Purvi Barot
  • 241
  • 2
  • 9