Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Reason for failing to Drop Column is showing non existent Index

Reason for failing to Drop Column is showing non existent Index

Scheduled Pinned Locked Moved Database
databasehelptools
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    indian143
    wrote on last edited by
    #1

    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+'"');
    END

    ALTER TABLE dbo.ApplicationData DROP COLUMN ReportingFpl;
    GO

    Error 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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups