Two system functions return information related to instances:
SERVERPROPERTY—This function takes one parameter and returns information about the server where the instance is installed. If the parameter is machinename, this function returns the name of the server. If the parameter used is servername, it returns the name of the server, along with the name of the instance. If instancename is used as the parameter, the function returns the name of the current instance, and if it's the default instance, it returns NULL. Listing A.3 shows how to use this function with the parameters described.
USE Master SELECT SERVERPROPERTY('machinename') SELECT SERVERPROPERTY('servername') SELECT SERVERPROPERTY('instancename') GO ------------------------- SQLBYEXAMPLE (1 row(s) affected) ------------------------- SQLBYEXAMPLEAPPENDIXA (1 row(s) affected) ------------------------- APPENDIXA (1 row(s) affected) |
@@SERVERNAME—This function returns the name of the server and current instance of SQL Server. This is equivalent to SERVERPROPERTY using the servername parameter. @@SERVERNAME is shown in Listing A.4.
USE Master SELECT @@SERVERNAME GO ------------------------- SQLBYEXAMPLEAPPENDIXA (1 row(s) affected) |
3.133.114.221