Breaking News
Loading...
02/10/2013

Kiểm tra 1 Stored Procedure có tồn tại hay không trong SQL Server

1 việc thường làm ở công ty là khi tạo mới 1 stored procedure, phải viết code kiểm tra stored có tồn tại hay không, nếu chưa có thì mới tạo mới. Ví dụ:

/****** Object:  StoredProcedure [dbo].[usp_Configuration_SetDataLoadEmailNotification]    Script Date: 10/2/2013 1:46:14 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO

IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usp_Configuration_SetDataLoadEmailNotification]') AND type in (N'P', N'PC'))
EXEC dbo.sp_executesql @statement = N'
-- =============================================
-- Author:  Vinh Mai
-- Create date: May 13, 2013
-- Description: 
-- =============================================
CREATE PROCEDURE [dbo].[usp_Configuration_SetDataLoadEmailNotification]
@Email nvarchar(200)
AS
BEGIN
  Update Configuration Set ConfigValue=@Email where ConfigID=N''DataLoadEmailNotification'' 
END'

0 comments:

Post a Comment

 
Toggle Footer