Skip to content

Instantly share code, notes, and snippets.

@robsmith1776
Created January 31, 2024 13:57
Show Gist options
  • Save robsmith1776/bc528455f4121c9a83041594c0f09b0f to your computer and use it in GitHub Desktop.
Save robsmith1776/bc528455f4121c9a83041594c0f09b0f to your computer and use it in GitHub Desktop.
get views
declare @tsql varchar(max) = 'SELECT
a.code, b.customer_name
FROM table_a a
INNER JOIN table_b b ON a.code = b.code
WHERE NOT EXISTS (SELECT 1
FROM table_c c
WHERE a.code = c.code)'
exec ('create view vwtmp as ' + @tsql)
select OBJECT_NAME(referencing_id) referencing_entity,
o.[type_desc] as referenced_entity_type, referenced_entity_name
from sys.sql_expression_dependencies d
inner join sys.objects o
on d.referenced_id = o.[object_id]
where OBJECT_NAME(referencing_id) = 'vwtmp'
exec ('drop view vwtmp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment