“OBJECT_NAME” function no longer returns objects' names

  • I use the "OBJECT_NAME' function in conjunction with systems tables to return the names of objects given their object_id. Up until yesterday, this worked fine. When I use the same function now, I get a null value in the column that is supposed to return the object name. I tried reconnecting to the server and trying the function on different DBs, but I am getting the same results. Does anyone know why this would occur?

  • It still works. But it will give a null result if the number isn't valid in the context of the connection it's being run in.

    If, for example, the connection is to master, and the object_id you are querying is for something in a user database, then odds are you'll get NULL, unless master uses the same number for a different object.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I wasn't specifying the database to use. I explicitly designated the DB to use in the session and the names reappeared

  • if you run this command, are the results null for the ObjectName? I've never heard of the built in function not working correctly, it's usually because of the issues Gsqared mentions, wrong object_id(doesn't exist) or wraong database context.

    SELECT

    OBJECT_NAME(object_id) As ObjectName,

    object_id,

    name

    FROM sys.objects

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • guerillaunit (8/16/2012)


    I wasn't specifying the database to use. I explicitly designated the DB to use in the session and the names reappeared

    Okay. That means it was connecting to the default databases for your login (almost always master). That makes sense.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply