Judging whether object existed in the database, if it does, delete it.

-- If user table existed, delete it.
if   exists  ( select   *   from  sysobjects  where  id = object_id (N ' dbo.tblHeadCountForecast_Upload ' and   OBJECTPROPERTY (id,N ' IsUserTable ' ) = 1
    
drop   table  tblHeadCountForecast_Upload

-- If StoreProcedure existed, delete it.
if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[CalculateRunRateDollar] ' and   OBJECTPROPERTY (id, N ' IsProcedure ' =   1 )
drop   procedure   [ dbo ] . [ CalculateRunRateDollar ]

-- If function existed, delete it.
if    exists  ( select   *   from  sys.objects  where   object_id   =   object_id (N ' [dbo].[SplitForUpdateForecast] ' and  type  in  (N ' FN ' , N ' IF ' , N ' TF ' , N ' FS ' , N ' FT ' ))
DROP   FUNCTION   [ dbo ] . [ SplitForUpdateForecast ]
 

你可能感兴趣的:(object,function,upload,table,database,delete)