sqlServer存储过程
1、创建存储过程报错:
'CREATE/ALTER PROCEDURE' 必须是查询批次中的第一个语句。
解决方法:
use databaseName
后面要加上一句:
GO
二、标准创建案例
-
use BeerHouse
-
go
-
-- drop procedure prSearchStudent
-
if OBJECT_ID('prSearchStudent') is not null drop procedure prSearchStudent
-
go
-
create procedure prSearchStudent
-
as
-
begin
-
select FStuName from Student
- end
创建前使用预判,sqlserver和mysql的预判语法有些出入:
sqlserver:
if BJECT_ID(‘procName’) is not null drop procedure procName
mysql:
drop procedure is existes procName
注意事项
直接如下使用,当没有该存储过程时会报错:
drop procedure prSearchStudent