Sunday, March 25, 2012

DB_NAME anomaly

On my SP3 db_name(0) and db_name(1) are returning the same thing. Can anybody else try this? Beta of Yukon is doing the same thing...But the following code returns 1:

select db_id(db_name(0))I think that is expected behavior. Try running:USE master
GO
SELECT db_id(db_name(0)), db_id(db_name(1)), db_name(0)
USE tempdb
GO
SELECT db_id(db_name(0)), db_id(db_name(1)), db_name(0)
USE model
GO
SELECT db_id(db_name(0)), db_id(db_name(1)), db_name(0)
USE msdb
GO
SELECT db_id(db_name(0)), db_id(db_name(1)), db_name(0)
USE pubs
GO
SELECT db_id(db_name(0)), db_id(db_name(1)), db_name(0)To see if you get:
-- -- ---------------------------------------
1 1 master

(1 row(s) affected)


-- -- ---------------------------------------
2 1 tempdb

(1 row(s) affected)


-- -- ---------------------------------------
3 1 model

(1 row(s) affected)


-- -- ---------------------------------------
4 1 msdb

(1 row(s) affected)


-- -- ---------------------------------------
5 1 pubs

(1 row(s) affected)-PatP|||Got it, db_name(0) is the same as db_name(), - the current database.

The reason I asked was because sysprocesses have house-keeping-related processes with dbid=0 which are being reported to have no database context. Once I changed "where db_name(dbid) is not null" to "where dbid > 0" everything worked OK.|||The reason I asked was because sysprocesses have house-keeping-related processes......

Sure it does.. :D
Now who's on crack huh?

by the way how is that sp_recompile going.. :D

No comments:

Post a Comment