我们有多个SQL Server,其中大多数都是独立的。我需要创建一个存储过程/视图,将所有数据库名称插入到所有服务器的表中。从多个服务器获取所有数据库名称
有没有办法通过存储过程或视图来做到这一点?我没有任何PowerShell或.Net的经验。
这是我到目前为止。我只是无法弄清楚如何从服务器跳转到服务器,并将所有结果添加到真实的表格中。
CREATE TABLE ##temp
(
DATABASE_NAME VARCHAR(100),
DATABASE_SIZE INT,
REMARKS VARCHAR(500)
)
INSERT into ##temp
EXEC [sp_databases]
--doing this to also get ServerName along with the db name.
--When I insert into a real table, I'll seperate it into two columns plus remove "@[email protected]"
update ##temp
set DATABASE_NAME = (select @@SERVERNAME) + '@[email protected] ' + DATABASE_NAME
where DATABASE_NAME not like '%@[email protected]%'
select DATABASE_NAME from ##temp
你可以通过'Registered Servers'窗口对多个服务器执行查询 –