How can I get the SQL Server server and instance name of the current connection, using a T-SQL script?
To get the list of server and instance that you're connected to:
select * from Sys.Servers
To get the list of databases that connected server has:
SELECT * from sys.databases;