Results 1 to 4 of 4

Thread: DB_NAME anomaly

  1. #1
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662

    Unanswered: 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))
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I think that is expected behavior. Try running:
    Code:
    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:
    Code:
                                                                                                                                                   
    ------ ------ -------------------------------------------------------------------------------------------------------------------------------- 
         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

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    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 data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  4. #4
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    The reason I asked was because sysprocesses have house-keeping-related processes........
    Sure it does..
    Now who's on crack huh???

    by the way how is that sp_recompile going..
    Last edited by Ruprect; 12-08-04 at 16:27.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •