IF EXISTS (SELECT DATA_TYPE 
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE TABLE_NAME = 'MISTable'
  AND COLUMN_NAME = 'ProductWareLinkNumber'
  AND DATA_TYPE = 'int'
)
BEGIN
  DECLARE @sql NVARCHAR(2000)
  DECLARE @ConstraintName VARCHAR(256)
  DECLARE @IdxName VARCHAR(256)

  -- Change on MISTable
  -- DROP default value
  SELECT @ConstraintName = default_constraints.name
  FROM sys.all_columns
  INNER JOIN sys.tables ON all_columns.object_id = tables.object_id
  INNER JOIN sys.schemas ON tables.schema_id = schemas.schema_id
  INNER JOIN sys.default_constraints ON all_columns.default_object_id = default_constraints.object_id
  WHERE schemas.name = 'dbo'
  AND tables.name = 'MISTable'
  AND all_columns.name = 'ProductWareLinkNumber'

  IF ISNULL(@ConstraintName, '') <> ''
  BEGIN
    SET @sql = N'ALTER TABLE MISTable DROP CONSTRAINT ' + @ConstraintName
    EXEC sp_executesql @sql
  END

  -- DROP index's
  -- Index's are recreated by script post\AddIndexMISSelect.sql
  DECLARE #TempCur CURSOR SCROLL STATIC FOR
    SELECT sysind.name
    FROM sys.indexes sysind 
    INNER JOIN sys.index_columns sysind_col ON sysind.object_id = sysind_col.object_id 
      AND sysind.index_id = sysind_col.index_id 
    INNER JOIN sys.columns sys_col ON sysind_col.object_id = sys_col.object_id 
      AND sysind_col.column_id = sys_col.column_id 
    INNER JOIN sys.tables systab ON sysind.object_id = systab.object_id
    WHERE systab.is_ms_shipped = 0 
    AND sysind.is_primary_key = 0 
    AND sys_col.name  = 'ProductWareLinkNumber'
    AND systab.name = 'MISTable'
  OPEN #TempCur

  FETCH NEXT FROM #TempCur INTO @IdxName

  WHILE @@FETCH_STATUS = 0
  BEGIN
    SET @sql = N'DROP INDEX ' + @IdxName + ' ON MISTable'
    EXEC sp_executesql @sql
    FETCH NEXT FROM #TempCur INTO @IdxName
  END

  CLOSE #TempCur
  DEALLOCATE #TempCur

  ALTER TABLE MISTable ALTER COLUMN ProductWareLinkNumber BIGINT NOT NULL
  ALTER TABLE MISTable ADD DEFAULT -1 FOR ProductWareLinkNumber
END

IF EXISTS (SELECT DATA_TYPE 
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE TABLE_NAME = 'MISTablePackSum'
  AND COLUMN_NAME = 'ProductWareLinkNumber'
  AND DATA_TYPE = 'int'
)
BEGIN
  -- Change MISTablePackSum
  -- DROP primary key
  SELECT @ConstraintName = name  
  FROM sys.key_constraints  
  WHERE type = 'PK' AND OBJECT_NAME(parent_object_id) = N'MISTablePackSum';

  IF ISNULL(@ConstraintName, '') <> ''
  BEGIN
    SET @sql = N'ALTER TABLE MISTablePackSum DROP CONSTRAINT ' + @ConstraintName
    EXEC sp_executesql @sql
  END

  ALTER TABLE MISTablePackSum ALTER COLUMN ProductWareLinkNumber BIGINT NOT NULL
  ALTER TABLE MISTABLEPackSum ADD CONSTRAINT [PK_MISTABLEPackSum] PRIMARY KEY CLUSTERED (ProductWareLinkNumber ASC)
END