存储过程内容如下:
use #books
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- 删除原有存储过程
if exists(select name from sysobjects where name='user_d')
drop proc user_dCREATE PROCEDURE user_d 
@KH nchar(10)='00001'
AS
BEGIN  
SET NOCOUNT ON;
delete from [dbo].[Users_HB] where US_KaHao=@KH  

END
GO错误提示如下:
消息 111,级别 15,状态 1,过程 user_d,第 11 行
'CREATE/ALTER PROCEDURE' 必须是查询批次中的第一个语句。

解决方案 »

  1.   


    if exists(select name from sysobjects where name='user_d') 
    drop proc user_d 
    go        --加个GOCREATE PROCEDURE user_d 
    @KH nchar(10)='00001' 
    AS 
    BEGIN 
    SET NOCOUNT ON; 
    delete from [dbo].[Users_HB] where US_KaHao=@KH  END 
    GO 
      

  2.   

    use #books 
    SET ANSI_NULLS ON 
    GO 
    SET QUOTED_IDENTIFIER ON 
    GO 
    -- ============================================= 
    -- 删除原有存储过程 
    if exists(select name from sysobjects where name='user_d') 
    drop proc user_d 
    go
    CREATE PROCEDURE user_d 
    @KH nchar(10)='00001' 
    AS 
    BEGIN 
    SET NOCOUNT ON; 
    delete from [dbo].[Users_HB] where US_KaHao=@KH  END 
    GO 
      

  3.   

    if exists(select name from sysobjects where name='user_d') 
    drop proc user_d 
    goCREATE PROCEDURE user_d 
    @KH nchar(10)='00001' 
    AS 
    BEGIN 
    SET NOCOUNT ON; 
    delete from [dbo].[Users_HB] where US_KaHao=@KH  END 
    GO 
      

  4.   

    if exists(select name from sysobjects where name='user_d') 
    drop proc user_d GO
      

  5.   

    没有那个GO的话CREATE PROCEDURE 就不是第一个执行的语句了 于是就报错