Uploaded image for project: 'DdlUtils'
  1. DdlUtils
  2. DDLUTILS-127

MsSqlBuilder does not drop foreign keys to a table before dropping the table.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.0 RC1
    • Core - SqlServer
    • None

    Description

      Could not drop object 'Tmp_categories' because it is referenced by a FOREIGN KEY constraint. Query: IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'Tmp_categories')
      BEGIN
      DECLARE @tablename nvarchar(256), @constraintname nvarchar(256)
      DECLARE refcursor CURSOR FOR
      SELECT object_name(objs.parent_obj) tablename, objs.name constraintname
      FROM sysobjects objs JOIN sysconstraints cons ON objs.id = cons.constid
      WHERE objs.xtype != 'PK' AND object_name(objs.parent_obj) = 'Tmp_categories' OPEN refcursor
      FETCH NEXT FROM refcursor INTO @tablename, @constraintname
      WHILE @@FETCH_STATUS = 0
      BEGIN
      EXEC ('ALTER TABLE '@tablename' DROP CONSTRAINT '+@constraintname)
      FETCH NEXT FROM refcursor INTO @tablename, @constraintname
      END
      CLOSE refcursor
      DEALLOCATE refcursor
      DROP TABLE Tmp_categories
      END;

      Attachments

        1. DDLUTILS-127.patch
          1.0 kB
          Christoffer Hammarström

        Activity

          People

            tomdz Thomas Dudziak
            kreiger Christoffer Hammarström
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: