Harsha M V
Harsha M V

Reputation: 54949

MySQLt Workbench Constraints

I am using MySQL Workbench to create my data models. When i try to export the sql. it creates the Constraints for the Foreign keys.

If there anyway i can prevent that to happen ?

What are the advantages of Constraints ?

Upvotes: 0

Views: 545

Answers (1)

Sergio
Sergio

Reputation: 4567

I fail to see the problem there. According to the MySQL Documentation you can define foreign keys for your tables in your column definition list or in separate constraint clauses.

So this code:

CREATE TABLE ReferencingTable (
  id         INT PRIMARY KEY,
  other_id   INT REFERENCES ReferencedTable (id)
);

Is equivalent to this code:

CREATE TABLE ReferencingTable (
  id         INT PRIMARY KEY,
  other_id   INT,
  CONSTRAINT FOREIGN KEY (other_id) REFERENCES ReferencedTable (id)
);

The difference is just a syntactic one and shouldn't matter to you.

Of course, you can instruct MySQL Workbench to just not forward engineer your foreign keys. This is available both in the Export/Forward Engineering dialogs and as a checkbox when editing a given table's foreign key. Here's the option in the Export dialog:

enter image description here

Upvotes: 1

Related Questions