|
130 | 130 | {% macro sqlserver__list_relations_without_caching(schema_relation) -%} |
131 | 131 | {% call statement('list_relations_without_caching', fetch_result=True) -%} |
132 | 132 | {{ get_use_database_sql(schema_relation.database) }} |
133 | | - with base as ( |
134 | | - select |
135 | | - DB_NAME() as [database], |
136 | | - t.name as [name], |
137 | | - SCHEMA_NAME(t.schema_id) as [schema], |
138 | | - 'table' as table_type |
139 | | - from sys.tables as t {{ information_schema_hints() }} |
140 | | - union all |
141 | | - select |
142 | | - DB_NAME() as [database], |
143 | | - v.name as [name], |
144 | | - SCHEMA_NAME(v.schema_id) as [schema], |
145 | | - 'view' as table_type |
146 | | - from sys.views as v {{ information_schema_hints() }} |
147 | | - ) |
148 | | - select * from base |
149 | | - where [schema] like '{{ schema_relation.schema }}' |
| 133 | + declare @schema_id int = schema_id('{{ schema_relation.schema }}'); |
| 134 | + select |
| 135 | + DB_NAME() as [database], |
| 136 | + t.name as [name], |
| 137 | + '{{ schema_relation.schema }}' as [schema], |
| 138 | + 'table' as table_type |
| 139 | + from sys.tables as t {{ information_schema_hints() }} |
| 140 | + where t.schema_id = @schema_id |
| 141 | + union all |
| 142 | + select |
| 143 | + DB_NAME() as [database], |
| 144 | + v.name as [name], |
| 145 | + '{{ schema_relation.schema }}' as [schema], |
| 146 | + 'view' as table_type |
| 147 | + from sys.views as v {{ information_schema_hints() }} |
| 148 | + where v.schema_id = @schema_id |
150 | 149 | {{ get_query_options() }} |
151 | 150 | {% endcall %} |
152 | 151 | {{ return(load_result('list_relations_without_caching').table) }} |
|
155 | 154 | {% macro sqlserver__get_relation_without_caching(schema_relation) -%} |
156 | 155 | {% call statement('get_relation_without_caching', fetch_result=True) -%} |
157 | 156 | {{ get_use_database_sql(schema_relation.database) }} |
158 | | - with base as ( |
159 | | - select |
160 | | - DB_NAME() as [database], |
161 | | - t.name as [name], |
162 | | - SCHEMA_NAME(t.schema_id) as [schema], |
163 | | - 'table' as table_type |
164 | | - from sys.tables as t {{ information_schema_hints() }} |
165 | | - union all |
166 | | - select |
167 | | - DB_NAME() as [database], |
168 | | - v.name as [name], |
169 | | - SCHEMA_NAME(v.schema_id) as [schema], |
170 | | - 'view' as table_type |
171 | | - from sys.views as v {{ information_schema_hints() }} |
172 | | - ) |
173 | | - select * from base |
174 | | - where [schema] like '{{ schema_relation.schema }}' |
175 | | - and [name] like '{{ schema_relation.identifier }}' |
| 157 | + declare @schema_id int = schema_id('{{ schema_relation.schema }}'); |
| 158 | + select |
| 159 | + DB_NAME() as [database], |
| 160 | + t.name as [name], |
| 161 | + '{{ schema_relation.schema }}' as [schema], |
| 162 | + 'table' as table_type |
| 163 | + from sys.tables as t {{ information_schema_hints() }} |
| 164 | + where t.schema_id = @schema_id and t.name = '{{ schema_relation.identifier }}' |
| 165 | + union all |
| 166 | + select |
| 167 | + DB_NAME() as [database], |
| 168 | + v.name as [name], |
| 169 | + '{{ schema_relation.schema }}' as [schema], |
| 170 | + 'view' as table_type |
| 171 | + from sys.views as v {{ information_schema_hints() }} |
| 172 | + where v.schema_id = @schema_id and v.name = '{{ schema_relation.identifier }}' |
176 | 173 | {{ get_query_options() }} |
177 | 174 | {% endcall %} |
178 | 175 | {{ return(load_result('get_relation_without_caching').table) }} |
|
183 | 180 | {% endmacro %} |
184 | 181 |
|
185 | 182 | {% macro sqlserver__get_view_definition_sql(relation) -%} |
| 183 | + {%- set object_name = "quotename('" ~ relation.schema ~ "') + '.' + quotename('" ~ relation.identifier ~ "')" -%} |
186 | 184 | {{ get_use_database_sql(relation.database) }} |
187 | | - select object_definition(v.object_id) as definition |
188 | | - from sys.views as v {{ information_schema_hints() }} |
189 | | - inner join sys.schemas as s {{ information_schema_hints() }} |
190 | | - on v.schema_id = s.schema_id |
191 | | - where upper(s.name) = upper('{{ relation.schema }}') |
192 | | - and upper(v.name) = upper('{{ relation.identifier }}') |
| 185 | + select object_definition(object_id({{ object_name }}, 'V')) as definition |
| 186 | + where object_id({{ object_name }}, 'V') is not null |
193 | 187 | {% endmacro %} |
194 | 188 |
|
195 | 189 | {% macro sqlserver__get_relation_last_modified(information_schema, relations) -%} |
|
0 commit comments