开发者

List of all servers and databases

开发者 https://www.devze.com 2023-02-19 17:54 出处:网络
I want to write a stored procedure that lists the name of all the servers and their corresponding databases. I know that I can use osql/sqlcmd utility to list all the servers. But \'osql -L\'开发者_开

I want to write a stored procedure that lists the name of all the servers and their corresponding databases. I know that I can use osql/sqlcmd utility to list all the servers. But 'osql -L'开发者_开发知识库 doesnot support any other parameters with it like another -Q that can list all the databases. I would want to pull both servernames and their databases using the same query. Is there a way to do it?


CREATE TABLE #servers(sname VARCHAR(255))
INSERT #servers (sname)
EXEC master..xp_CMDShell 'ISQL -L'
DELETE
FROM #servers
WHERE sname='Servers:'
OR sname IS NULL
SELECT LTRIM(sname)
FROM #servers
DROP TABLE #servers
0

精彩评论

暂无评论...
验证码 换一张
取 消