SQL SERVER – How to Build Three Part Name from Object_ID – Part 2?

Earlier this week, I posted an interesting interview question How to Build Three Part Name from Object_ID? – Interview Question of the Week #134. In its response, I have received a very interesting reply from Rin Sitah over here.

Rin suggested an alternative method to my earlier suggested method which works just fine and also builds three part name from the object_ID.

Well, honestly, I love this new method much more than my original method, hence decided to write this blog post.

SELECT '['+DB_Name()+'].['+s.name+'].['+o.name+']'
FROM sys.objects o
INNER JOIN sys.schemas s
ON s.schema_id = o.schema_id
WHERE object_ID = 1154103152

Well, let me know which method you prefer in either case.

SQL SERVER - How to Build Three Part Name from Object_ID - Part 2? threepart-800x393

Additionally, I had asked users if they can tell me where exactly they use this method and interesting enough the majority answer I have received that user use this method when they want to do some kind of administration maintenance. Honestly, I still think DBA and developers should write code which is more dependant on a combination of name and schema and not on object_id. It is quite possible if the table is regenerated with different object_id.

Well, that’s it. Let me know if you think of any other idea in the comment section of this blog post.

Reference: Pinal Dave (https://blog.sqlauthority.com)

SQL Function, SQL Scripts, SQL Server, System Object
Previous Post
SQL SERVER – How to Convert CollationID to Collation Name?
Next Post
SQL SERVER – Difference Between spid, kpid and ecid in sysprocesses

Related Posts

4 Comments. Leave new

Leave a ReplyCancel reply

Exit mobile version