Difference between Alter Table Foreign Key

Asked

Viewed 395 times

9

I would like to know the difference between the execution in the clauses Alter Table when inserting the ADD CONSTRAINT , such as running the following code:

ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);

What’s the difference in using this code:

ALTER TABLE Orders
ADD CONSTRAINT FK_PersonOrder
FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);

There are improvements in performance, security, or some information that is important to know when it comes to database?
And taking advantage of the question, exactly what makes the ADD CONSTRAINT?(Currently I use MySQL)

2 answers

10


ADD CONSTRAINT -> To allow naming a FOREIGN KEY constraint and to set a FOREIGN KEY constraint in multiple columns.

  • The difference would be in the name of the restriction created, in the first case would be added a random default name, example (Fk__orders__personid__1e2636f2), in the second case will be created with name(Fk_personorder), being possible to be accessed and changed by some system, knowing the name of FK.

5

The addition of ADD CONSTRAINT is used to define the name of the FOREIGN KEY and to create foreign key with multiple columns.

more information

Browser other questions tagged

You are not signed in. Login or sign up in order to post.