我有 100 个数据库,我需要对一个过程进行更改,它们都有相同的过程。如何添加允许我进行此更改的光标?
DECLARE @databasename varchar(100)
DECLARE @Command nvarchar(200)
DECLARE database_cursor CURSOR FOR
SELECT name
FROM MASTER.sys.sysdatabases
OPEN database_cursor
FETCH NEXT FROM database_cursor INTO @databasename
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @Command = 'ALTER PROCEDURE ''' + @databasename + '''.[dbo].[DeleteAccountUpgrade]
@Id INT
AS
DELETE FROM AccountUpgrades WHERE Id = @Id'
EXEC sp_executesql @Command
FETCH NEXT FROM database_cursor INTO @databasename
END
CLOSE database_cursor
DEALLOCATE database_cursor
它说我需要声明@Id,但我不明白为什么,我只想在每个数据库上运行该更改,我没有发送任何数据来执行该过程,我只想修改所有数据库上的现有过程。