SQL Server error 1750: Could not create constraint or index
A constraint or index couldn't be created. 1750 is the closing message; the error just before it (such as 1505 duplicate key, 2714 or 547) is the cause.
- Error number
1750- Severity
- 10
- Category
- Constraints and keys
What it means
SQL Server reports 1750 after another error prevented ALTER TABLE ... ADD CONSTRAINT or an index creation. It says nothing on its own; look at the error immediately before it.
Common causes
- Existing duplicate rows when adding a primary key or unique constraint.
- Existing rows that violate a new foreign key or check constraint (error 547).
- A constraint name already used in the schema (error 2714).
- Referencing a parent column that has no primary key or unique constraint when creating a foreign key.
How to fix it
-
Read the preceding error and fix that first.
-
For duplicates blocking a new unique key, find them.
SELECT Email, COUNT(*) FROM dbo.Customers GROUP BY Email HAVING COUNT(*) > 1;
-
A foreign key must reference a primary key or unique constraint on the parent.
ALTER TABLE dbo.Customers ADD CONSTRAINT UQ_Customers_Code UNIQUE (Code); ALTER TABLE dbo.Orders ADD CONSTRAINT FK_Orders_Customers FOREIGN KEY (CustomerCode) REFERENCES dbo.Customers (Code);
Related errors
2714There is already an object named547Statement conflicted with a constraint2627Violation of PRIMARY KEY or UNIQUE KEY1913Index or statistics name already exists
More constraints and keys errors
2601Cannot insert duplicate key row515Cannot insert the value NULL into column3726Can't drop: referenced by a FOREIGN KEY4712Can't truncate a referenced table1505Duplicate key found, unique index
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.