Let's say we have a table called Salesman with the folling properties
Create Table SalesMan(
EmplyeeId int Primary Key,
Name varchar(20) Not Null,
LastName Varchar(20) Not Null,
Email Varchar(40) Unique);
and a simple table definition for "Order"
Create Table Orders(
Number Varchar(20),
Quantity Int,
DealerCode Varchar(20),
ModelName Varchar(20),
ModelVersion Varchar(20));
At this point I forgot to add a One to Many relation between Order and Salesman so that a SalesMan can have many orders and Orders can have only one Salesman
Alter Table Orders Add sm_fk int;
Alter Table Orders Add Constraint Sales_fk Foreign Key (sm_fk) References SalesMan(EmplyeeId)
Now my question is: could I have simplified the query by omitting the second alter table query and compress it to
Alter Table Orders add sm_fk int References SalesMan(EmplyeeId)
Would this be the same as the second Alter Table query?
Thank you for your time!
ALTER TABLE
allows to specify more than one action, so both queries may be combined into one - in such case both constraint symbol and index name may be specified.