Created
January 31, 2024 13:57
-
-
Save robsmith1776/bc528455f4121c9a83041594c0f09b0f to your computer and use it in GitHub Desktop.
get views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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