我想在Pervasive数据库中创建一个存储过程,但前提是它尚不存在。
我找到了适合SQL Server的东西:
IF NOT EXISTS (SELECT *
FROM sys.objects
WHERE type = 'P' AND OBJECT_ID = OBJECT_ID('dbo.MyProc'))
exec('CREATE PROCEDURE [dbo].[MyProc] AS BEGIN SET NOCOUNT ON; END')
GO
我在此链接上找到了代码How to check if a stored procedure exists before creating it。
所以我想要一些与Pervasive非常相似的东西。
答案 0 :(得分:1)
无法在Pervasive中的存储过程之外执行IF NOT EXISTS
语法。您可以创建一个采用过程名称的过程,如果存在则将其删除。类似的东西:
CREATE PROCEDURE DropProcIfExists(in :procname char(20))
AS
BEGIN
IF( EXISTS (SELECT xp$Name FROM X$proc WHERE Xp$Name = :procname) ) THEN
Exec('DROP Procedure "' + :procname + '"') ;
END IF;
End#
call DropProcIfExists ('myProc')#
所以你的SQL会是这样的:
call DropProcIfExists('MyNewProc')#
Create Procedure MyNewProc()
AS
BEGIN...