Find that Forgotten Object Name | Database Journal

Find that Forgotten Object Name

Written By
Alan Enderby
Alan Enderby
Oct 2, 2000
1 minute read

Forget what that table or stored procedure was called ?
Want to produce a repetitive command with different object names ?

Sp_findobj will give you
the name of all the objects containing a
given string.

You can also
supply TSQL to go before and after the object name.

Example

Exec
sp_findobj ‘stock’, ‘dump table’, ‘to stock_backup’

Will give
dump
table stock_control to stock_backup
dump table stock_items to
stock_backup
dump table stock_status to stock_backup
dump table
stock_status_history to stock_backup
dump table stock_status_rules to
stock_backup
dump table stock_transfer_rules to stock_backup

You can
cut & past this into the query window and execute it

Use
master
go
if exists (select * from sysobjects where id =

object_id(‘dbo.sp_findobj’) and sysstat & 0xf = 4)
drop procedure
dbo.sp_findobj
GO

/****** Object: Stored Procedure dbo.sp_findobj
Script Date:
02/09/96 13:16:05 ******/
create proc sp_findobj
@with
varchar(30) ,
@head varchar(132) =’Select * from’ ,
@tail varchar(132) =”
,
@type char(255)=’u’
as

select @with = ‘%’ + @with + ‘%’
select
@head + ‘ ‘ + name + ‘ ‘ + @tail
from sysobjects
where upper(name) like
upper(@with)
and type =@type
order by name

GO

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.