use Goods
declare @oldtableName varchar(50)
declare @newtableName varchar(50)
declare @db varchar(32)
declare @use varchar(50)
declare alter_table cursor for
SELECT 库名,原表名,新表名 from GoodsTable
open alter_table
fetch next from alter_table into @db,@oldtableName,@newtableName
while @@FETCH_STATUS = 0
begin
Set @use=‘History’+@db
EXEC ('USE '+ @use);
-- 这里就有问题了,
EXEC sp_rename @oldtableName, @newtableName
fetch next from alter_table into @db,@oldtableName,@newtableName
end
CLOSE alter_table
DEALLOCATE alter_table