Jan
14
2015
SQL // Tools

SQL Query to search databases for object by name

I didn't write this, as usual I found it on Stack Overflow and other places. I had a need to search a SQL database for tables, views, and columns that contained certain key words.  This has been very helpful.

 

 Declare @ObjectName VarChar (100)

Set @ObjectName = '%post%'

Select 'QTR_CC_SEA' as DatabaseName, [name] as ObjectName, Type as ObjectType
From QTR_CC_SEA.Sys.Objects
Where 1=1
and [Name] like @ObjectName
and Type in ('U', 'P')

SELECT COLUMN_NAME, TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE @ObjectName
AND COLUMN_NAME not like 'tbl_aud%'

 

Comments are closed

Calendar

<<  June 2017  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

View posts in large calendar

Page List

    RecentComments

    None