Difference between using or not using CONSTRAINT keyword on SQL Server
constraints, sql, sql-server
Solution
If you don't create constraint.it will automatically create own constraint name
the foreign key index name is generated using the name of the referencing foreign key column Automatically.
So there is no way to see difference of using and not using Constraint keyword. by default constraint name will be defined.
Problem
What is the difference between using or not using the `CONSTRAINT` keyword when working with Foreign Keys on SQL Server? I noticed that apparently both worked the same in this specific case, without `CONSTRAINT`: ``` CREATE TABLE ClientsPhones ( ClientPhone varchar(10) NOT NULL, ClientID smallint NOT NULL, PRIMARY KEY (ClientPhone), FOREIGN KEY (ClientID) REFERENCES Clients(ClientID) ); ``` And with `CONSTRAINT`: ``` CREATE TABLE ClientsPhones ( ClientPhone varchar(10) NOT NULL, ClientID smallint NOT NULL, PRIMARY KEY (ClientPhone), CONSTRAINT fk_ClientID FOREIGN KEY (ClientID) REFERENCES Clients(ClientID) ); ``` Both didn't let me add records to the table unless the `ClientID` already existed on the `Clients` table, and the same `ClientID` and `ClientPhone` weren't already on the `ClientsPhones` table. Is there any real difference between the two besides the fact that I'm able to name the constraint?