如何用存储过程创建一个存储过程
delcare @txt char(1024)
set @txt = 'if exists (select * from dbo.sysobjects where id = object_id(N ' '[dbo].[m0000] ' ') and OBJECTPROPERTY(id, N ' 'IsPROCEDURE ' ') = 1) ' +
' begin ' +
' DROP PROCEDURE [dbo].[m0000] ' +
' print ' 'PROCEDURE exist, drop it ' ' ' +
' end ' +
' create PROCEDURE [dbo].[m0000] ( ' +
' As) '
但是帮助提示我说,create procedure 必须为第一句,请问有什么方法可以绕过去
总的要求就是如何用存储过程创建一个存储过程,当发现存储过程存在时,可以先删除老的存储过程,再新建新的存储过程
------解决方案--------------------declare @txt char(1024)
set @txt = 'if exists (select * from dbo.sysobjects where id = object_id(N ' '[dbo].[m0000] ' ') and OBJECTPROPERTY(id, N ' 'IsPROCEDURE ' ') = 1) ' +
' begin ' +
' DROP PROCEDURE [dbo].[m0000] ' +
' print ' 'PROCEDURE exist, drop it ' ' ' +
' end ' +
' exec( ' 'create PROCEDURE [dbo].[m0000] ' +
' As ...... ' ') '
exec(@txt)