问题描述
当我执行数据库脚本时,我在存储过程中出错,然后它无法创建有错误的存储过程.即使存储过程发生错误,我也想强行创建存储过程.
When I execute database script, I got errors in stored procedure then it couldn't create that stored procedure that have errors. I want to forcibly create stored procedure even if some error occur in stored procedure.
如果在 create procedure 语句中发生错误,则不会创建存储过程.我想要的是无论如何都会创建存储过程,无论是否发生错误.
If some error occurred in the create procedure statement it won't create stored procedure. What I want is that stored procedure will be created anyway, whether an error occurred or not.
实际上我们在 SQL Server 2000 中有数据库,我在 SQL Server 2005 中附加了它,然后将兼容级别更改为 90.最后我想执行该脚本,但我也希望如果发生某些错误,它将忽略错误并创建对象.
Actually we have database in SQL Server 2000, I attached it in SQL Server 2005 and then change the compatibility level to 90. And finally I want to execute the script but I also want that if some error occurred then it will ignore error and create the objects.
推荐答案
您可以通过以不能失败的方式创建存储过程来强制创建它.看这个例子:
You can force the creation of a stored procedure by creating it in a can't-fail way. See this example:
if object_id('sp_name') is null
exec sp_executesql N'create procedure dbo.sp_name as select 1'
go
alter procedure db.sp_name
as
...
go
现在如果更改失败,无论如何都会有一个存储过程.
Now if the alter fails, there will be a stored procedure anyway.
这篇关于即使发生错误,如何强制创建存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!