Database Programming: OBJECT_ID Takes Three-Part Identifiers

This is another one of those tricks that’s been available since the earth was cooling, but I just discovered it recently.

So, here’s a history lesson in the form of a small T-SQL script, with the moral contained in the title of this post:

set nocount on
use master
select  object_id(‘sysobjects’) as ObjectIdFromMaster

use tempdb

select  object_id(‘master.dbo.sysobjects’) as ObjectIdFromTempdb

select  id as ObjectIdFromCatalogView
from    master.dbo.sysobjects
where   name = ‘sysobjects’

All three SELECT statements return the same result, proving that the OBJECT_ID function will indeed properly process a three-part name:




This works all the way back to SQL Server 2000, which is the oldest platform I’ve got conveniently available.

Thanks to my colleague Venkata Raj Pochiraju for showing me this classic.


Comments (2)

  1. Anonymous says:

    This post is a cousin of sorts to last December’s post regarding the OBJECT_ID function. I learned this

  2. alex says:

    programming a lot of information and knowledge the programmer need logic and experience to create an application or project,