Click here to Skip to main content
15,887,683 members
Articles / Database Development / SQL Server / SQL Server 2008
Tip/Trick

Get my database server with current database.

Rate me:
Please Sign up or sign in to vote.
4.75/5 (13 votes)
24 Feb 2010CPOL 13.4K   9  
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.

SQL
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.[^]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
-- There are no messages in this forum --