Reason for failing to Drop Column is showing non existent Index
-
Hi All, I have written a small sql script to drop a table and recreate it but it is failing, I tried to drop all existing indexes on the table and column then trying to drop the column, but still fails by saying there is one constraint that's missing, and I don't know why but that constraint doesn't exist in database. Here is the script that I am writing
DECLARE @ConstraintName nvarchar(200);
DECLARE @TableName nvarchar(500)='ApplicationData';
DECLARE @ColumnName nvarchar(500)='ReportingFpl';SET NOCOUNT ON
SET xact_abort ON
WHILE 0=0 BEGIN
SET @constraintName = (
SELECT TOP 1 constraint_name
FROM information_schema.constraint_column_usage
WHERE table_name = @tableName and column_name = @columnName );
IF @constraintName is null BREAK;
EXEC ('alter table "'+@tableName+'" drop constraint "'+@constraintName+'"');
ENDALTER TABLE dbo.ApplicationData DROP COLUMN ReportingFpl;
GOError Message
Msg 5074, Level 16, State 1, Line 16
The index 'IX_ApplicationData_ApplicationId-ReportingFpl_PriorityPoints-ContractorPriorityPoints' is dependent on column 'ReportingFpl'.
Msg 4922, Level 16, State 9, Line 16
ALTER TABLE DROP COLUMN ReportingFpl failed because one or more objects access this column.But the constraint 'IX_ApplicationData_ApplicationId-ReportingFpl_PriorityPoints-ContractorPriorityPoints' doesn't exist in the constraint table at all. Can anybody please help me in resolving this issue, any link, any suggestion or code snippet helps greatly. Thanks in advance.
Thanks & Regards, Abdul Aleem Mohammad St Louis MO - USA