a. Column Level
GO
CREATE TABLE Products
(
ProductID INT CONSTRAINT pk_products_pid PRIMARY KEY,
ProductName VARCHAR(25)
);
GO
b. Table Level
CREATE TABLE Products
(
ProductID INT,
ProductName VARCHAR(25),
CONSTRAINT pk_products_pid PRIMARY KEY(ProductID)
);
GO
Is their any difference between Column level and table level constraints?
No. It’s just a matter of personal taste how you apply the constraint.
The primary key constraint is just a primary key constraint – it always applies to the table (after all: it could contain multiple columns – it cannot be “at the column level”).
It’s not “at the column level” once or at the “table level” in the other case – it’s the same always.
Just for fun – you can also create the primary key constraint a third way:
and that again would be identical to the two other options you already have.