System Functions Used in Multi-Instance Installations

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.

Code Listing A.3. Using the SERVERPROPERTY Function
					
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.

Code Listing A.4. Using the @@SERVERNAME Function
					
 USE Master

SELECT @@SERVERNAME
GO
-------------------------

SQLBYEXAMPLEAPPENDIXA

(1 row(s) affected) 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.114.221