create procedure dbo.testproc
as
begin
declare @dynamicsql nvarchar(100)
set @dynamicsql='insert into table1 values(''abc'',30)'
exec @dynamicsql
end
create procedure sampleproc
as
begin
select * from table1
end
我需要通过动态地将其重命名为“testproc_new”来获取从 testproc 调用的过程sampleproc。我应该如何实现这个目标?我在dynamicsql中添加了create proc语句并执行,但它没有给我结果。
sp_rename
与动态 sql 一起使用:
DECLARE @oldname varchar(100), @newname varchar(100);
SET @oldname = <old sp name>
SET @newname = @oldname + CONVERT(varchar(20), GETDATE(), 120)
EXEC sp_rename @oldname,@newname
Keep @newname as "testproc_new"