Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Getting Server, Database, and user name

Author  Topic 

DrewBurlingame
Starting Member

49 Posts

Posted - 2005-12-08 : 12:43:05
Is there a way from within a script to get the name of the server, database and user for the current scope?

I have a script that will vary slightly depending on which server and database it's run on, and another script that will vary based on the user that is logged in.

Thanks,
Drew

DrewBurlingame
Starting Member

49 Posts

Posted - 2005-12-08 : 15:17:11
@@SERVERNAME gets the name of the server the script is running in.

Any one have any ideas for databasename and user name?

Thanks,
Drew
Go to Top of Page

nu_dba
Starting Member

8 Posts

Posted - 2005-12-08 : 15:22:47
I believe you will be able to use the DB_NAME and Current_User functions.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_7msw.asp

Hope that helps.

-- nu_dba
Go to Top of Page

DrewBurlingame
Starting Member

49 Posts

Posted - 2005-12-08 : 18:04:17
Perfect. I knew they were there, I just couldn't remember the names of the functions. Thanks nu_dba.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-09 : 01:33:08
Also
Select DB_name()
select user_name()

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-12-09 : 14:46:36
You coudl always look them up in books online
Go to Top of Page
   

- Advertisement -