Finding Objects in SQL Server During Development

I kept writing the same SQL over and over while developing to find the names of stored procs or to see what objects I had recently added.  So I created a quick stored proc that I now have in my toolbox.

create proc obj(@name varchar(50)=null, @type char(1)=null)
as
begin
set nocount on

select o.name, 
o.type, 
convert(varchar(10),o.create_date,1) created, 
convert(varchar(10),o.modify_date,1) modified
from sys.objects o
where (@name is null or o.name like @name)
and (@type is null or o.type = @type)
and o.is_ms_shipped = 0
order by o.modify_date desc

end
go

So if I just do:
obj ‘get%’, ‘P’

I’ll get:

 

nametypecreatedmodified
GetProjectsTreeP7/28/20082/27/2010
GetProjectOutputVariablesP10/10/20092/26/2010
GetXrefRequestIssueP9/9/20082/11/2010
GetProjectOutputVariableP2/11/20102/11/2010
GetRequestsItemsOverlapP1/6/20102/9/2010
GetControlP2/6/20102/6/2010
getSourceIdFromPathP2/5/20102/5/2010
GetRequestedFilesP10/14/20082/2/2010
GetRequestsForBranchP12/30/20081/15/2010
GetRequestWithChildrenP7/28/20081/1/2010
GetRequestsItemsP4/28/20091/1/2010

And if I call obj with no parameters, I will get a list of all my objects with the most recently modified objects first. This works with SQL 2005 and above.

Leave a Comment

Your email address will not be published. Required fields are marked *