To find a specific text from whole database we
can be either of the following queries.
The sys.object holds all the tables, Stored
Procedures, Views, etc. that are available in a database within a server.
Similarly the INFORMATION_SCHEMA.ROUTINES holds the DB object within a DB.
--Searching for xyz table
SELECT Name
FROM sys.objects
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%xyz%'
GO
--Searching for xyz table and abcd column together
SELECT Name
FROM sys.objects
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%xyz%'
AND OBJECT_DEFINITION(OBJECT_ID) LIKE '%abcd%'
GO
--Searching for SEARCHSTRING text (it can be table, column, etc.,) and routine
type is procedure
SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%SEARCHSTRING%'
AND ROUTINE_TYPE='PROCEDURE'
No comments:
Post a Comment