Sunday, June 10, 2012

How to query database schema and objects

Run select statement against system object information_schema.tables for tables list and information_schema.columns for columns list

Example
Select table_name from information_schema.tables where table_name like '%cust%'

Select column_name from information_schema.columns where table_name = 'customers'

Sp sp_help [object] can be also helpful

How to find stored procedure that contains the given text

SELECT DISTINCT so.name FROM sys.sysobjects so 
INNER JOIN sys.syscomments sc ON sc.id=so.id 
WHERE sc.TEXT LIKE '%your tesxt%'

No comments:

Post a Comment