首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-09-14 
判断 函数 存储过程 用法SQL codeif not exists (select * from dbo.sysobjects where id object_id(N[

判断 函数 存储过程 用法

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或者前面什么语句都没有

热点排行
Bad Request.