Difference between the Alter Table Foreign Key

8

I would like to know the difference between the execution of the Alter Table clauses when entering the ADD CONSTRAINT , for example by executing 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);

Are there improvements in performance, security, or any information that is important to know when it comes to database?
And taking advantage of the question,  exactly what does ADD CONSTRAINT do? (I currently use MySQL )

    
asked by anonymous 31.03.2017 / 22:00

2 answers

9

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

  • The difference would be in the name of the constraint created, in the first case would be added a random default name, example (FK__Orders__PersonID__1E2636F2), in the second case it will be created with name (FK_PersonOrder), being possible to be accessed and changed by some system, knowing the name of the FK.
05.04.2017 / 22:48
5

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

more information

    
05.04.2017 / 00:32