pietlinden - Sunday, February 19, 2017 4:56 PM
Absolutely. Other than the name, the difference is that the constraint is defined separately from the column.
Of course, the real difference is that Gail's example of Stations and Star Systems is much cooler than my boring Employees table. 😛
IF OBJECT_ID('dbo.Employees', 'u') IS NOT NULL DROP TABLE dbo.Employees;
IF OBJECT_ID('dbo.Departments', 'u') IS NOT NULL DROP TABLE dbo.Departments;
CREATE TABLE dbo.Departments (
ID Integer not null identity (1, 1),
constraint Employees_PK PRIMARY KEY (ID),
Name Varchar(32) not null,
EntryDate Datetime,
UpdateDate Datetime);
CREATE TABLE dbo.Employees (
ID Integer not null identity (1, 1),
constraint EmployeesNVC_PK PRIMARY KEY (ID),
FirstName Nvarchar(32) not null,
LastName Nvarchar(32) not null,
DepartmentID Integer not null,
CONSTRAINT Employees_Departments_FK
FOREIGN KEY (DepartmentID)
REFERENCES dbo.Departments (ID),
HireDate Datetime not null);