当前位置: 代码迷 >> Sql Server >> 判断 函数 存储过程 用法,该怎么解决
  详细解决方案

判断 函数 存储过程 用法,该怎么解决

热度:519   发布时间:2016-04-27 11:21:00.0
判断 函数 存储过程 用法
SQL code
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[test1]'))begin   select 1   create table test1(id int)end goif not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[test]'))begin   create proc test(@p_id int )   as   begin      select 3   end end go


上述代码创建表的时候没有问题,但是创建存储过程的时候却报错“消息 156,级别 15,状态 1,第 4 行
关键字 'proc' 附近有语法错误。”

存储过程的代码为什么只能这样写
SQL code
if  exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[test]'))  drop proc testgocreate proc test(@p_id int )asbegin  select 3end   go


------解决方案--------------------
存储过程的create proc语句必须是程序块的第一句才可以,也就是说在create proc前面必须接go或者前面什么语句都没有
  相关解决方案