How to Delete an Index in SQL Server

If you find yourself with an index in SQL Server that you no longer need, you may decide to disable it, or you may opt to get rid of it altogether. That way you can declutter your database, free up space, and perhaps help improve performance of updates to the data.

Typically, to delete an index in SQL Server, we use the DROP INDEX statement. There are cases where we might drop it via other means (for example, if it’s implemented as part of a PRIMARY KEY or UNIQUE constraint – also shown below), but DROP INDEX is usually the go to command for such operations.

Continue reading

Fix Error 11415 “Object … cannot be disabled or enabled. This action applies only to foreign key and check constraints” in SQL Server

If you’re getting SQL Server error 11415 that reads something like “Object ‘UQ_Employees_Email’ cannot be disabled or enabled. This action applies only to foreign key and check constraints“, it’s probably because you’re trying to disable either a DEFAULT, UNIQUE or PRIMARY KEY constraint.

Continue reading

Fix Error 1987 “Cannot alter nonclustered index … because its clustered index is disabled” in SQL Server

If you’re getting SQL Server error 1987 that reads something like “Cannot alter nonclustered index ‘UQ_Employees_Email’ on table ‘Employees’ because its clustered index is disabled“, it’s probably because you’re trying to rebuild a nonclustered index when the clustered index for the table is disabled.

To fix this issue, either enable/rebuild the table’s clustered index first, then try again, or enable all indexes at once.

The clustered index will typically be the primary key index (unless you’ve specified another clustered index for the table).

Continue reading

Fix Error 4512 “Cannot schema bind view” in SQL Server Due to “two-part format” Issue

If you’re getting an error that reads something like “Cannot schema bind view ‘vEmployees’ because name ‘Employees’ is invalid for schema binding. Names must be in two-part format and an object cannot reference itself” it could be that you’re trying to create a schema bound view, but you’re not using a two-part format for names (such as the table names within the view).

Continue reading

Fix Error 1505 “The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name” in SQL Server

If you’re getting an error that reads something like “The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name” it’s probably because you’re trying to create a UNIQUE constraint on a column that already contains duplicate values.

Continue reading

Fix Error “Drop table operation failed on table … because it is not a supported operation on system-versioned temporal tables” in SQL Server

If you’re getting an error that reads something like “Drop table operation failed on table ‘db.dbo.TableName’ because it is not a supported operation on system-versioned temporal tables” in SQL Server, it’s probably because you’re trying to drop a temporal table that still uses system-versioning.

In SQL Server, if a table is defined as a temporal table, we can’t drop it while it’s using system-versioning.

If you really want to drop the table, turn off system-versioning first, then try again.

Continue reading

Fix Error 2788 “Synonyms are invalid in a schemabound object or a constraint expression” in SQL Server

If you’re getting SQL Server error 2788 that reads “Synonyms are invalid in a schemabound object or a constraint expression” it seems that you’re trying (whether intentionally or not) to create a schemabound object that includes a synonym in its definition, or a constraint with a synonym in its expression.

Continue reading

Fix Error “Truncate failed on table … because it is not a supported operation on system-versioned tables.” in SQL Server

If you’re getting an error that reads something like “Truncate failed on table ‘test.dbo.ProductInventory’ because it is not a supported operation on system-versioned tables.” in SQL Server, it’s probably because you’re trying to truncate a system-versioned temporal table.

In SQL Server, if a table is defined as a temporal table, we can’t truncate it while it’s using system-versioning.

Continue reading

Fix “date/time field value out of range” in PostgreSQL

If you’re getting an error that reads ‘date/time field value out of range‘ in PostgreSQL while using a function such as date_add(), date_subtract(), or date_trunc(), it’s probably because the date value you’re passing to the function is an invalid date.

It’s possible that you’ve got the month and day in the wrong order.

To fix this issue, be sure that you pass a valid date. It may be that all you need to do is switch the day and the month around. Or it could be that you need to change your datestyle setting.

Continue reading