Sunday, January 17, 2010

Searching SQL Database for Keyword

If you want to search an SQL data base (specifically SQL 2005) for a Keyword, use the following code changing KEYWORD to the term you are searching for:

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%KEYWORD%'
AND ROUTINE_TYPE='PROCEDURE'
ORDER BY ROUTINE_NAME

SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%KEYWORD%'
AND ROUTINE_TYPE='FUNCTION'
ORDER BY ROUTINE_NAME

SELECT NAME
FROM sysobjects
WHERE id IN ( SELECT id FROM syscolumns WHERE NAME like '%KEYWORD%' )

No comments: