Click here to Skip to main content
Click here to Skip to main content

Get my database server with current database.

By , 24 Feb 2010
Rate this:
Please Sign up or sign in to vote.
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.[^]

License

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

About the Author

Md. Marufuzzaman
CEO
Bangladesh Bangladesh
n/a
Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140421.2 | Last Updated 25 Feb 2010
Article Copyright 2010 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid