sql脚本如下, 检查数据库中是否有存储过程,删除掉并创建
-----存储过程1
IF exists (select * from sysobjects where id = object_id(N'SP_GET_IDENT_NO') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE SP_GET_IDENT_NO
GO
CREATE PROCEDURE SP_GET_IDENT_NO(@INAME VARCHAR(10),@identNo VARCHAR(20) OUTPUT)
AS
BEGIN
------------XXXXX
END
-----存储过程2
IF exists (select * from sysobjects where id = object_id(N'SP_GET_IDENT_NO_COMPLAIN') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE SP_GET_IDENT_NO_COMPLAIN
GO
CREATE PROCEDURE SP_GET_IDENT_NO_COMPLAIN(@INAME VARCHAR(10),@identNo VARCHAR(20) OUTPUT)
AS
BEGIN
数据库中有存储过程1,2,
在次执行sql时,
提示
‘数据库中已存在名为 'SP_GET_IDENT_NO_COMPLAIN' 的对象。’
IF exists (select * from sysobjects where id = object_id(N'SP_GET_IDENT_NO_COMPLAIN') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE SP_GET_IDENT_NO_COMPLAIN
这里的 sql不管用么?
我单独执行 存储1,存储2就可以删除、创建;
这里怎么回事?
------解决方案--------------------
try this,
-----存储过程1
IF exists (select * from sysobjects where id = object_id(N'SP_GET_IDENT_NO')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE SP_GET_IDENT_NO
go
CREATE PROCEDURE SP_GET_IDENT_NO(@INAME VARCHAR(10),@identNo VARCHAR(20) OUTPUT)
AS
BEGIN
------------XXXXX
END
go
-----存储过程2
IF exists (select * from sysobjects where id = object_id(N'SP_GET_IDENT_NO_COMPLAIN')
and OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE SP_GET_IDENT_NO_COMPLAIN
go
CREATE PROCEDURE SP_GET_IDENT_NO_COMPLAIN(@INAME VARCHAR(10),@identNo VARCHAR(20) OUTPUT)
AS
BEGIN
------------XXXXX
end
go