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
 SQL Server Administration (2000)
 Database Id

Author  Topic 

Sarat
Constraint Violating Yak Guru

265 Posts

Posted - 2003-06-10 : 17:47:55
Hi,
I have dev server which has 3 databases (Dev, Upg 1 and Upg 2). In profiler I chose Database Id as a column, how do I know which database has which id? The trace shows sometimes 5, 7 , 11 etc.
Thanks,
Sarat

**To be intoxicated is to feel sophisticated, but not be able to say it.**

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-06-10 : 18:07:05
SELECT id, name
FROM sysdatabases

I believe that there is a function that you can call to get it too, but the above select is easy enough.

Tara
Go to Top of Page

Sarat
Constraint Violating Yak Guru

265 Posts

Posted - 2003-06-10 : 18:08:44
Hey Tara, Thanks!!
I also selected database name as one of the columns but nothing appears on that while i am doing bunch of selects in QA.
-Sarat

**To be intoxicated is to feel sophisticated, but not be able to say it.**
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-06-10 : 18:13:03
For some reason, some of the events do not provide the database name, hostname, and other items. I haven't figured out why though.

Tara
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-06-10 : 18:57:13
Some system processes don't technically run in a database (SQL Agent, replication agents, lazywriter) so those columns in sysprocesses may be empty.

DB_NAME() will give you the name of a database ID, and DB_ID() performs the reverse function. Lately I've come to use these and the OBJECT_ID/OBJECT_NAME functions A LOT, they are very handly and eliminate the need to join tables just to get a name for something.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-06-10 : 18:59:57
quote:

Some system processes don't technically run in a database (SQL Agent, replication agents, lazywriter) so those columns in sysprocesses may be empty.



But shouldn't Sarat's SELECT queries show the database name?

quote:

DB_NAME() will give you the name of a database ID, and DB_ID() performs the reverse function. Lately I've come to use these and the OBJECT_ID/OBJECT_NAME functions A LOT, they are very handly and eliminate the need to join tables just to get a name for something.



Yeah I use those when I can remember the function names. Sarat, just so that you know these are listed in BOL under meta data..functions.

Tara
Go to Top of Page

Sarat
Constraint Violating Yak Guru

265 Posts

Posted - 2003-06-10 : 19:56:50
Another Q:
I know that there is a property where trace stops after certain time specified by you. I forgot to set that now I don't want to stop the trace but is there a way to edit trace options while it is running? For ex: if i pause, will it let me change any properties - i guess not but checking since i want to go home! I think i will let it run overnight.
Thanks,
Sarat.

**To be intoxicated is to feel sophisticated, but not be able to say it.**
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-06-11 : 12:09:05
No you can not modify the properties once the trace starts. You have to stop it first, modify the properties, then start it again. If you save it to a different table name or file name after you stop it though, you shouldn't miss much data.

Tara
Go to Top of Page

jasper_smith
SQL Server MVP & SQLTeam MVY

846 Posts

Posted - 2003-06-11 : 13:08:20
quote:
But shouldn't Sarat's SELECT queries show the database name?


The only events you'll see the database name for are Security Audit events. Things should improve in the future [url]http://tinyurl.com/e23k[/url]


HTH
Jasper Smith

0x73656c6563742027546f6f206d7563682074696d65206f6e20796f75722068616e6473203f27
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-06-11 : 13:13:08
Thanks Jasper. That's good to know.

Tara
Go to Top of Page

monkeybite
Posting Yak Master

152 Posts

Posted - 2003-06-11 : 13:22:24
The system sproc [sp_helpdb] will show you info about all the databases on the server, including database id (dbid). Give it a database name as a parameter, and it'll show you more detail about just that db.

~ monkey



Edited by - monkeybite on 06/11/2003 13:23:14
Go to Top of Page

debug
Starting Member

29 Posts

Posted - 2003-06-11 : 17:19:19
DB_NAME() and DB_ID() functions are quickest and easiest way to find out the DB Id and Db name.

DU
Go to Top of Page
   

- Advertisement -