SQL SERVER – Find any expression in the database

Posted by Joggee | SQL Server 2005, SQL Server 2008, SQL Sever, SQL Tips and Tricks | Thursday 28 February 2008 10:56 am

My colleagues asked me hundred times, how to find a particular columns, table name, stored procedure, views in the database.

Always forgot to remember one query. So for them only :)

Below query you can any table, stored procedure or views who ever have that expression as a column or object name.

SELECT * FROM SYSOBJECTS WHERE ID IN (SELECT ID FROM SYSCOMMENTS WHERE TEXT LIKE ‘%PRODUC%’)

The query produced all the object names. where ever it finds expression like ‘PRODUC

If you wanted to find any table name only then

SELECT * FROM SYSOBJECTS WHERE NAME LIKE ‘%TA%’ and xtype=‘u’

result

For stored procedure  pass  xtype=‘p’ and for views xtype=‘v’

Hope next time my friends will visit from my blog to get this query ;)

Rana

1 Comment »

  1. Comment by ado.net programming — July 8, 2008 @ 9:28 pm

    nice one. Many many years ago I wrote a “find in sp” windows app for finding an expression inside the sp code. I will try to locate the source and add these as well, cause returning name matches would sure be nice as well.

RSS feed for comments on this post. TrackBack URI

Leave a comment