检查并执行存储过程

时间:2012-08-04 20:20:04

标签: sql-server-2008

我正在尝试检查存储过程是否存在,然后我需要执行它。当我尝试这个时,我在if部分遇到错误:

use [ST_Analysis]
GO
/***** Object:  StoredProcedure [dbo].[sp_CleanRelogTables]  
INPUT PARAMETERS
none
*****/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

IF NOT EXISTS(SELECT  name FROM sysobjects WHERE name = 'sp_CleanRelogTables' 
              AND type = 'P')
begin
    CREATE PROCEDURE [dbo].[sp_CleanRelogTables]
    AS
    BEGIN
        SET NOCOUNT ON
        TRUNCATE TABLE COUNTERDATA
        TRUNCATE TABLE COUNTERDETAILS
        SET NOCOUNT OFF
    END
end
Else
    execute sp_CleanRelogTables

0 个答案:

没有答案