IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_MoveChildSurfaceFromParentToGrandParent]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_MoveChildSurfaceFromParentToGrandParent]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SetSurfaceDataItemFromLinks]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SetSurfaceDataItemFromLinks]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SetSurfaceDataFromLinks]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SetSurfaceDataFromLinks]
END

IF EXISTS ( SELECT * 
            FROM   sysobjects 
            WHERE  id = object_id(N'[dbo].[sp_SaveSurfaceItemQueryTable]') 
                   and OBJECTPROPERTY(id, N'IsProcedure') = 1 )
BEGIN
    DROP PROCEDURE [dbo].[sp_SaveSurfaceItemQueryTable]
END

IF EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'currentBalance'
      AND Object_ID = Object_ID(N'pal_SMSCredit'))
BEGIN
    ALTER TABLE pal_SMSCredit
	DROP COLUMN currentBalance 
END
IF EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'allocatedBalance'
      AND Object_ID = Object_ID(N'pal_SMSCredit'))
BEGIN
    ALTER TABLE pal_SMSCredit
	DROP COLUMN allocatedBalance 
END
IF EXISTS(
    SELECT *
    FROM sys.columns 
    WHERE Name      = N'availableBalance'
      AND Object_ID = Object_ID(N'pal_SMSCredit'))
BEGIN
    ALTER TABLE pal_SMSCredit
	DROP COLUMN availableBalance 
END

IF EXISTS (SELECT *
           FROM   sys.objects
           WHERE  object_id = OBJECT_ID(N'[dbo].[fn_GetSMSCreditBalance]')
                  AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
  DROP FUNCTION [dbo].[fn_GetSMSCreditBalance]

IF EXISTS (SELECT *
        FROM   sys.objects
        WHERE  object_id = OBJECT_ID(N'[dbo].[fn_GetSMSCreditAllocatedBalance]')
                AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION [dbo].[fn_GetSMSCreditAllocatedBalance]
