Skip to content

Instantly share code, notes, and snippets.

@felipeabajo
Created August 5, 2025 15:20
Show Gist options
  • Select an option

  • Save felipeabajo/be3c9b1adddf7d6f80475f8c28caa225 to your computer and use it in GitHub Desktop.

Select an option

Save felipeabajo/be3c9b1adddf7d6f80475f8c28caa225 to your computer and use it in GitHub Desktop.
References of a table in a BD
DECLARE @SearchText NVARCHAR(255) = 'table_name';
SELECT
OBJECT_SCHEMA_NAME(sm.[object_id]) AS [Schema],
OBJECT_NAME(sm.[object_id]) AS [ObjectName],
o.type_desc AS [ObjectType],
sm.[definition] AS [SQLDefinition]
FROM sys.sql_modules sm
INNER JOIN sys.objects o ON sm.[object_id] = o.[object_id]
WHERE sm.[definition] LIKE '%' + @SearchText + '%'
ORDER BY [Schema], [ObjectName];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment