/*
IF EXISTS (SELECT 1 
           FROM sys.foreign_keys 
           WHERE 
             object_id = OBJECT_ID(N'[dbo].[FK_CUSTOMER_VatValue]') AND 
             parent_object_id = OBJECT_ID(N'[dbo].[Customer]'))
-- MSSQL doesn´t like this syntax, therefore..            
*/              
IF EXISTS (SELECT 1
/*
  sod.name as [dst_table],
  so.name as [dst_key],
  sos.name as [src_table]
*/
           FROM sysobjects so WITH (NOLOCK)  
             JOIN sysreferences sr (NOLOCK) ON sr.constid = so.id
             JOIN sysobjects sod (NOLOCK) ON sod.id = so.parent_obj
             JOIN sysobjects sos (NOLOCK) ON sos.id = sr.rkeyid
          WHERE
            sod.name = 'Customer' AND
            so.name = 'FK_CUSTOMER_VatValue')                   
BEGIN
  ALTER TABLE Customer
  DROP CONSTRAINT FK_CUSTOMER_VatValue
--SELECT 'Foreign key FK_CUSTOMER_VatValue in TABLE Customer dropped'
END
--ELSE SELECT 'Foreign key FK_CUSTOMER_VatValue in TABLE Customer does not exist' 
GO

IF EXISTS(SELECT 1 
          FROM INFORMATION_SCHEMA.COLUMNS 
          WHERE 
            TABLE_NAME = 'Customer' AND 
            COLUMN_NAME = 'VatValueNumber')
BEGIN
  ALTER TABLE Customer 
  DROP COLUMN VatValueNumber
--SELECT 'Column VatValueNumber in TABLE Customer dropped'
END
--ELSE SELECT 'Column VatValueNumber in TABLE Customer does not exist' 
GO

IF EXISTS (SELECT 1 
           FROM INFORMATION_SCHEMA.TABLES 
           WHERE 
             TABLE_TYPE = 'BASE TABLE' AND 
             TABLE_NAME = 'VatValue')
BEGIN
  DROP TABLE VatValue
--SELECT 'TABLE VatValue dropped'
END
--ELSE SELECT 'TABLE VatValue does not exist' 
GO