A set of system functions that can provide data on a per-connection, per-database, or server-wide basis is provided.
The kind of information available ranges from static information (such as the database server name) to detailed performance-related statistics (such as disk and memory usage).
The following functions retrieve system information:
This function provides the value of a given property on a server-wide basis.
These functions provide the value of a given property for a given database, or by default, for the current database.
These functions provide the value of a given property for a given connection, or by default, for the current connection.
Supply as an argument only the name of the property you want to retrieve. The functions return the value for the current server, connection, or database.
For better performance, a client application monitoring database activity should use the PROPERTY_NUMBER function to identify a named property, and then use the number to repeatedly retrieve the statistic.
Property names obtained in this way are available for many different database statistics, from the number of transaction log page write operations and the number of checkpoints performed, to the number of reads of index leaf pages from the memory cache.
The following set of statements illustrates the process from Interactive SQL:
CREATE VARIABLE propnum INT; CREATE VARIABLE propval INT; SET propnum = PROPERTY_NUMBER( 'CacheRead' ); SET propval = DB_PROPERTY( propnum );
The following statement sets a variable named server_name to the name of the current server:
SET server_name = PROPERTY( 'name' );
The following query returns the user ID for the current connection:
SELECT CONNECTION_PROPERTY( 'UserID' );
The following query returns the file name for the root file of the current database:
SELECT DB_PROPERTY( 'file' );