Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database ID 2

Status
Not open for further replies.

mikemcginty

Programmer
Jul 11, 2002
184
0
0
AU
How do I retrieve the ID of the SQL database I am currently connected to?

I want to use sysprocesses to find out who is connected to the database but need to filter out user_names which are connected to other databases.

Regards

Mike

When you call out for help in the darkness, and you hear a voice in return, you're probably just talking to yourself again!
 
If you know the name of the database you specify it using the below call, but if you leave the parameter blank it defaults to the current DB
Code:
SELECT DB_ID('')


"I'm living so far beyond my income that we may almost be said to be living apart
 
Hmckillop, how in the world do you remember things like that? Is there a master list of those functions and/or switches that can be set?
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Just had to use it before and knew it was db_ something so looked in books online.

BTW congrats on being new tipmaster!

"I'm living so far beyond my income that we may almost be said to be living apart
 
Thanks.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top