In the following table definition, what is the difference between these two column definitions, or does the second just create an automatically named foreign key index?
CREATE TABLE dbo.Employee
(
dept_id int NOT NULL
CONSTRAINT fk_employee_deptid FOREIGN KEY REFERENCES Department(dept_id),
empType_id int NOT NULL REFERENCES EmployeeType(empType_id)
/* ... other columns ... */
);
The only difference is that the second one will be given a system generated name that will likely be more cryptic than one you allocate yourself.
The column name is also optional where there is an unambiguous possibility.
can also work. Again no difference in the end result. The full grammar for the FK declaration is
Optional items are enclosed in square brackets.