Table level constraint does not specify column list, table 'TableName'.

When creating Primary Key or Foreign Key like constraint, The following error occurred..

Table level constraint does not specify column list, table 'TableName'.

Meaning:
Column Name or Column List not specified for the constraints.

When creating Table:
IF OBJECT_ID('Tb_Table1','U') IS NULL
CREATE TABLE Tb_Table1
(
Id INT IDENTITY(1,1),
Column1 VARCHAR(10),
CONSTRAINT PK_Id PRIMARY KEY
)


or

When adding constraint on existing table:
ALTER TABLE Tb_Table1 ADD CONSTRAINT PK_Id PRIMARY KEY
GO


The error occurred, Here No column or Column list specified..

The script should be as follows...

IF OBJECT_ID('Tb_Table1','U') IS NULL
CREATE TABLE Tb_Table1
(
Id INT IDENTITY(1,1),
Column1 VARCHAR(10),
CONSTRAINT PK_Id PRIMARY KEY(Id)
)


or

ALTER TABLE Tb_Table1 ADD CONSTRAINT PK_Id PRIMARY KEY (Id)
GO

No comments:

Post a Comment