Tuesday, July 29, 2008

Find Objects in SQL Server

*********************************************************
** Find The Names And Types Of The T-SQL Objects
** Used In A Stored Procedure
**
** By: Dave Vroman
*********************************************************/
DECLARE @ProcName VARCHAR(50)
SET @ProcName = 'MyTestProc'

SELECT [Name],
CASE WHEN xType = 'C' THEN 'CHECK Constraint'
WHEN xType = 'D' THEN 'Default Or DEFAULT Constraint'
WHEN xType = 'F' THEN 'FOREIGN KEY Constraint'
WHEN xType = 'L' THEN 'Log'
WHEN xType = 'FN' THEN 'Scalar Function'
WHEN xType = 'IF' THEN 'Inlined Table-Function'
WHEN xType = 'P' THEN 'Stored Procedure'
WHEN xType = 'PK' THEN 'PRIMARY KEY Constraint (Type Is K)'
WHEN xType = 'RF' THEN 'Replication Filter Stored Procedure'
WHEN xType = 'S' THEN 'System Table'
WHEN xType = 'TF' THEN 'Table Function'
WHEN xType = 'TR' THEN 'Trigger'
WHEN xType = 'U' THEN 'User Table'
WHEN xType = 'UQ' THEN 'UNIQUE Constraint (Type Is K)'
WHEN xType = 'V' THEN 'View'
WHEN xType = 'X' THEN 'Extended Stored Procedure'
ELSE xType END AS xType
FROM sysobjects
WHERE id IN
(SELECT sd.depid FROM sysobjects so, sysdepends sd
WHERE so.name = @ProcName AND sd.id = so.id )

--------------------------------------------------
SELECT Distinct SO.Name, SO.Type
FROM sysobjects SO (NOLOCK)
INNER JOIN syscomments SC (NOLOCK) on SO.Id = SC.ID
--AND SO.Type = 'P' --U,P,V
AND SC.Text LIKE '%ObjectsName%' --need to be replicated
ORDER BY SO.Name
------------------------------------------------------

No comments:

Elevating LLM Deployment with FastAPI and React: A Step-By-Step Guide

  In a   previous exploration , I delved into creating a Retrieval-Augmented-Generation (RAG) demo, utilising Google’s gemma model, Hugging ...