为什么CREATE PROCEDURE语句时,我与IF语句在这里使用它失败? [英] Why does the CREATE PROCEDURE statement fail when I use it with IF Statement here?

查看:207
本文介绍了为什么CREATE PROCEDURE语句时,我与IF语句在这里使用它失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想如果存在要删除存储过程,然后通过做这样创建:

I am trying to DROP a stored procedure if it exists and then CREATE it by doing this way:

IF OBJECT_ID('[dbo].[myStoredProc]') IS not NULL
    DROP PROCEDURE dbo.myStoredProc


CREATE PROCEDURE [dbo].[myStoredProc]
(
    @parameter1 BIT
) AS

IF @parameter1 = 1
    BEGIN
             ....

但是,抱怨说:

CREATE PROCEDURE必须在该批次中唯一的语句

"CREATE PROCEDURE must be the only statement in the batch"

问:如何解决我的脚本来克服这种

Question: How can I fix my script to overcome this?

推荐答案

您需要把在你的第一个逻辑批处理结束。

You need to put a go at the end of your first logical batch.

IF OBJECT_ID('[dbo].[myStoredProc]') IS not NULL
    DROP PROCEDURE dbo.myStoredProc
go -- you need to add the batch-terminator 'go'


CREATE PROCEDURE [dbo].[myStoredProc]
(
    @parameter1 BIT
) AS

IF @parameter1 = 1
    BEGIN
             ..

这篇关于为什么CREATE PROCEDURE语句时,我与IF语句在这里使用它失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆