65.9K
CodeProject is changing. Read more.
Home

Get my database server with current database.

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.75/5 (13 votes)

Feb 25, 2010

CPOL
viewsIcon

13590

This is a very simple use of SQL Server global variables. Microsoft SQL Server provides a massive number of global variables, which are very effective to use in our regular Transact-SQL. Global variables represent a special type of variable. The server always maintain the values of these...

This is a very simple use of SQL Server global variables. Microsoft SQL Server provides a massive number of global variables, which are very effective to use in our regular Transact-SQL. Global variables represent a special type of variable. The server always maintain the values of these variables. All the global variables represent information specific to the server or a current user session. Global variable names begin with a @@ prefix. You do not need to declare them, since the server constantly maintains them. They are system-defined functions and you cannot declare them. The following transact-sql can be use for to Get the Server and Current database as well.
SELECT 'My Server is: ' + @@servername  AS DBServer
SELECT 'My Current Database is: ' +  db_name()  AS CurrentDataBase
For more information can be found at this link.[^]