不正确的语法:Create Procedure 必须是批处理中的唯一语句 [英] Incorrect Syntax: Create Procedure must be the only statement in the batch

查看:22
本文介绍了不正确的语法:Create Procedure 必须是批处理中的唯一语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前有人问过这个问题,但都涉及使用go",我在这里不需要,至少我相信是这样.

This question has been asked before but it all involved using "go" which I am not in need of here, at least I believe so.

我正在关注这个 tut https://www.youtube.com/watch?v=-xMGwiV5A6o,正好接近 1:25 标记.他的似乎执行而我的没有.

I am following this tut https://www.youtube.com/watch?v=-xMGwiV5A6o, near the 1:25 mark exactly. And his seems to execute while mine doesn't.

    Select * From Snacks

    Create Proc spGetSnackByID
    @Id int
    as

    Begin
    Select Id, Name, Location
    from Snacks where Id = @Id
    End

这是确切的错误,用BEGIN"语句突出显示:

Here is the exact error, being highlighted with the "BEGIN" statement:

"消息 111,级别 15,状态 1,过程 spGetSnackByID,第 7 行'CREATE/ALTER PROCEDURE' 必须是查询批处理中的第一条语句."

"Msg 111, Level 15, State 1, Procedure spGetSnackByID, Line 7 'CREATE/ALTER PROCEDURE' must be the first statement in a query batch."

推荐答案

是的,SQL Server 想要创建过程作为第一行.把上面的select注释掉,反正不是你想要的,因为你已经在存储过程中指定了字段.

Yes, SQL Server wants the create procedure as the first line. Just remark out the select above, it is not what you want anyway, because you have specified the fields in the stored procedure.

这篇关于不正确的语法:Create Procedure 必须是批处理中的唯一语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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