|
42 | 42 | {% macro sqlserver__list_relations_without_caching(schema_relation) -%} |
43 | 43 | {% call statement('list_relations_without_caching', fetch_result=True) -%} |
44 | 44 | {{ get_use_database_sql(schema_relation.database) }} |
45 | | - with base as ( |
46 | | - select |
47 | | - DB_NAME() as [database], |
48 | | - t.name as [name], |
49 | | - SCHEMA_NAME(t.schema_id) as [schema], |
50 | | - 'table' as table_type |
51 | | - from sys.tables as t {{ information_schema_hints() }} |
52 | | - union all |
53 | | - select |
54 | | - DB_NAME() as [database], |
55 | | - v.name as [name], |
56 | | - SCHEMA_NAME(v.schema_id) as [schema], |
57 | | - 'view' as table_type |
58 | | - from sys.views as v {{ information_schema_hints() }} |
59 | | - ) |
60 | | - select * from base |
61 | | - where [schema] like '{{ schema_relation.schema }}' |
| 45 | + declare @schema_id int = schema_id('{{ schema_relation.schema }}'); |
| 46 | + select |
| 47 | + DB_NAME() as [database], |
| 48 | + t.name as [name], |
| 49 | + '{{ schema_relation.schema }}' as [schema], |
| 50 | + 'table' as table_type |
| 51 | + from sys.tables as t {{ information_schema_hints() }} |
| 52 | + where t.schema_id = @schema_id |
| 53 | + union all |
| 54 | + select |
| 55 | + DB_NAME() as [database], |
| 56 | + v.name as [name], |
| 57 | + '{{ schema_relation.schema }}' as [schema], |
| 58 | + 'view' as table_type |
| 59 | + from sys.views as v {{ information_schema_hints() }} |
| 60 | + where v.schema_id = @schema_id |
62 | 61 | {{ apply_label() }} |
63 | 62 | {% endcall %} |
64 | 63 | {{ return(load_result('list_relations_without_caching').table) }} |
|
67 | 66 | {% macro sqlserver__get_relation_without_caching(schema_relation) -%} |
68 | 67 | {% call statement('get_relation_without_caching', fetch_result=True) -%} |
69 | 68 | {{ get_use_database_sql(schema_relation.database) }} |
70 | | - with base as ( |
71 | | - select |
72 | | - DB_NAME() as [database], |
73 | | - t.name as [name], |
74 | | - SCHEMA_NAME(t.schema_id) as [schema], |
75 | | - 'table' as table_type |
76 | | - from sys.tables as t {{ information_schema_hints() }} |
77 | | - union all |
78 | | - select |
79 | | - DB_NAME() as [database], |
80 | | - v.name as [name], |
81 | | - SCHEMA_NAME(v.schema_id) as [schema], |
82 | | - 'view' as table_type |
83 | | - from sys.views as v {{ information_schema_hints() }} |
84 | | - ) |
85 | | - select * from base |
86 | | - where [schema] like '{{ schema_relation.schema }}' |
87 | | - and [name] like '{{ schema_relation.identifier }}' |
| 69 | + declare @schema_id int = schema_id('{{ schema_relation.schema }}'); |
| 70 | + select |
| 71 | + DB_NAME() as [database], |
| 72 | + t.name as [name], |
| 73 | + '{{ schema_relation.schema }}' as [schema], |
| 74 | + 'table' as table_type |
| 75 | + from sys.tables as t {{ information_schema_hints() }} |
| 76 | + where t.schema_id = @schema_id and t.name = '{{ schema_relation.identifier }}' |
| 77 | + union all |
| 78 | + select |
| 79 | + DB_NAME() as [database], |
| 80 | + v.name as [name], |
| 81 | + '{{ schema_relation.schema }}' as [schema], |
| 82 | + 'view' as table_type |
| 83 | + from sys.views as v {{ information_schema_hints() }} |
| 84 | + where v.schema_id = @schema_id and v.name = '{{ schema_relation.identifier }}' |
88 | 85 | {{ apply_label() }} |
89 | 86 | {% endcall %} |
90 | 87 | {{ return(load_result('get_relation_without_caching').table) }} |
|
95 | 92 | {% endmacro %} |
96 | 93 |
|
97 | 94 | {% macro sqlserver__get_view_definition_sql(relation) -%} |
| 95 | + {%- set object_name = "quotename('" ~ relation.schema ~ "') + '.' + quotename('" ~ relation.identifier ~ "')" -%} |
98 | 96 | {{ get_use_database_sql(relation.database) }} |
99 | | - select object_definition(v.object_id) as definition |
100 | | - from sys.views as v {{ information_schema_hints() }} |
101 | | - inner join sys.schemas as s {{ information_schema_hints() }} |
102 | | - on v.schema_id = s.schema_id |
103 | | - where upper(s.name) = upper('{{ relation.schema }}') |
104 | | - and upper(v.name) = upper('{{ relation.identifier }}') |
| 97 | + select object_definition(object_id({{ object_name }}, 'V')) as definition |
| 98 | + where object_id({{ object_name }}, 'V') is not null |
105 | 99 | {% endmacro %} |
106 | 100 |
|
107 | 101 | {% macro sqlserver__get_relation_last_modified(information_schema, relations) -%} |
|
0 commit comments