SQL Server error 1913: Index or statistics name already exists
CREATE INDEX or CREATE STATISTICS used a name that already exists on that table or view. Index names are unique per table.
- Error number
1913- Severity
- 16
- Category
- Constraints and keys
What it means
Index and statistics names must be unique within a table or view (unlike constraint names, which are unique per schema). Re-running an index script, or creating an index with the same name as an existing statistics object, raises 1913.
Common causes
- Running a deployment script that creates an index twice.
- An index or statistics object with the same name was created earlier, possibly by a tuning tool.
How to fix it
-
Rebuild the existing index in place with
DROP_EXISTING.CREATE INDEX IX_Orders_CustomerId ON dbo.Orders (CustomerId) INCLUDE (OrderDate) WITH (DROP_EXISTING = ON);
-
Or guard the create.
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'dbo.Orders') AND name = N'IX_Orders_CustomerId') CREATE INDEX IX_Orders_CustomerId ON dbo.Orders (CustomerId); -
Check statistics names too.
SELECT name FROM sys.stats WHERE object_id = OBJECT_ID(N'dbo.Orders');
Related errors
2714There is already an object named2601Cannot insert duplicate key row42P07PostgreSQL: relation already exists1061MySQL: Duplicate key name
More constraints and keys errors
2627Violation of PRIMARY KEY or UNIQUE KEY547Statement conflicted with a constraint515Cannot insert the value NULL into column3726Can't drop: referenced by a FOREIGN KEY1750Could not create constraint or index4712Can'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.