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:
- Specified scale is invalid
- The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name
- Table already has a primary key defined on it
- Column name does not exist in the target table or view
- Violation of PRIMARY KEY constraint
- Column names in each table must be unique
- There is already an object named in the database