T-SQL Tutorial

Msg 1750 Level 16 - Could not create constraint or index


On Transact SQL language the Msg 1750 Level 16 - Could not create constraint or index means that the column was not defined not null.

Msg 1750 Level 16 Example:

We have the table MY_USERS:

USE tempdb;
GO
CREATE TABLE MY_USERS(
  ID INT ,
  NAME VARCHAR(100),
  JOIN_DATE DATE );
GO

Invalid alter:

USE tempdb;
GO
ALTER TABLE dbo.MY_USERS
ADD CONSTRAINT PK1_ID PRIMARY KEY CLUSTERED (ID);
GO

Message
Msg 8111, Level 16, State 1, Line 3
Cannot define PRIMARY KEY constraint on nullable column in table 'MY_USERS'.
Msg 1750, Level 16, State 0, Line 3
Could not create constraint or index. See previous errors.




Correct alter:

USE tempdb;
GO
ALTER TABLE dbo.MY_USERS
ALTER COLUMN ID INT NOT NULL ;
GO
ALTER TABLE dbo.MY_USERS
ADD CONSTRAINT PK1_ID PRIMARY KEY CLUSTERED (ID);
GO

Message
Command(s) completed successfully.

Other error messages: