to get the instance name: SELECT @@ServerName
to get the machine name of the server: SELECT SERVERPROPERTY(“MachineName”)
to get the machine name of the computer running the query: SELECT host_name()
one tip: cast the serverproperty as a varchar if you want to use it in a string or you will get errors in your stored procs/queries.
3 replies on “SQL Server: SELECT Machine, Computer, Instance Names”
[…] As a short follow up to a post I did a little while ago on SELECT’ing the instance and machine names from SQL Server, here is how you get the Current Database Name […]
LikeLike
Very helpful! Thanks.
LikeLike
WoW…. Excelent! This is what I needed…. Thanks friend’s….
Grettings!
LikeLike