Ward Pond's SQL Server blog

Ruminating on issues pertinent to the design and development of sound databases and processes under Microsoft SQL Server 2008, SQL Server 2005, and SQL Server 2000 (while reserving the right to vent about anything else that's on my mind)

Database Programming: OBJECT_ID Takes Three-Part Identifiers

Database Programming: OBJECT_ID Takes Three-Part Identifiers

  • Comments 2
  • Likes

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
go

use tempdb
go

select  object_id('master.dbo.sysobjects') as ObjectIdFromTempdb

select  id as ObjectIdFromCatalogView
from    master.dbo.sysobjects
where   name = 'sysobjects'
go

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

ObjectIdFromMaster
------------------
-105

ObjectIdFromTempdb
------------------
-105

ObjectIdFromCatalogView
-----------------------
-105

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.

     -wp

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

    http://www.cyberdesignz.com/

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

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment