We can declare a primary key inline
DECLARE @Employee TABLE (
EmpName VARCHAR(500), DOB DATE, AnnualSalary DECIMAL(10,2),
PRIMARY KEY (EmpName,DOB))
Or you can change PRIMARY KEY
for UNIQUE
if you want a non-primary key.
You can also declare it as an index and give it a name in SQL Server 2016+:
DECLARE @Employee TABLE (
EmpName VARCHAR(500), DOB DATE, AnnualSalary DECIMAL(10,2),
INDEX ix UNIQUE (EmpName,DOB))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…