sqlServer存储过程

1、创建存储过程报错:

    'CREATE/ALTER PROCEDURE' 必须是查询批次中的第一个语句。

sqlServer存储过程

解决方法:

use databaseName

后面要加上一句:

GO


二、标准创建案例


  1. use BeerHouse
  2. go
  3. -- drop procedure prSearchStudent
  4. if OBJECT_ID('prSearchStudent') is not null drop procedure prSearchStudent
  5. go
  6. create procedure prSearchStudent
  7. as
  8. begin
  9.     select FStuName from Student
  10. end


创建前使用预判,sqlserver和mysql的预判语法有些出入:

sqlserver:

if BJECT_ID(‘procName’) is not null drop procedure procName

mysql:

drop procedure is existes procName

注意事项

直接如下使用,当没有该存储过程时会报错:

drop procedure prSearchStudent