August 2012
Intermediate to advanced
1416 pages
33h 39m
English
System functions return information about the current environment. This section covers the two more commonly used system functions.
DB_NAME(): Returns the name of the current database, as shown in the following example:
SELECT CURRENT_TIMESTAMP AS [Date], DB_NAME() AS [Database];
Result:
Date Database ------------------------- ------- 2009-11-15 18:38:50.250 CHA2
SERVERPROPERTY(): Several useful pieces of information about the server may be determined from this function, including the following:
For example, the following code returns SQL Server engine edition and version information for my current instance of SQL Server:
SELECT
SERVERPROPERTY ('ServerName') AS ServerName,
SERVERPROPERTY ('Edition') AS Edition,
SERVERPROPERTY ('ProductVersion') AS ‘ProductVersion',
SERVERPROPERTY ('ProductLevel') AS ProductLevel;
Result:
ServerName Edition ProductVersion ProductLevel ----------- -------------- -------------- ------------- ------------ WIN-V7B3M53ERC1\DENALICTP3 Developer Edition (64-bit) 11.0.1422.17RTM ...
Read now
Unlock full access