sql server - Find DISTINCT Missing SQL Dependencies -
i have script returns invalid dependencies in database. script returns many duplicates. want see distinct
results.
/* modified version of script http://michaeljswart.com/2009/12/find-missing-sql-dependencies/ added columns object types & generated refresh module command... filter out user-define types: http://stackoverflow.com/questions/2330521/find-broken-objects-in-sql-server */ select top (100) percent quotename(object_schema_name(referencing_id)) + '.' + quotename(object_name(referencing_id)) [this object...], o.type_desc, isnull(quotename(referenced_server_name) + '.', '') + isnull(quotename(referenced_database_name) + '.', '') + isnull(quotename(referenced_schema_name) + '.', '') + quotename(referenced_entity_name) [... depends on missing entity name] ,sed.referenced_class_desc ,case when o.type_desc in( 'sql_stored_procedure' ,'sql_scalar_function' ,'sql_trigger' ,'view') 'exec sys.sp_refreshsqlmodule ''' + quotename(object_schema_name(referencing_id)) + '.' + quotename(object_name(referencing_id)) + ''';' else null end [refresh sql module command] sys.sql_expression_dependencies sed left join sys.objects o on sed.referencing_id=o.object_id (is_ambiguous = 0) , (object_id(isnull(quotename(referenced_server_name) + '.', '') + isnull(quotename(referenced_database_name) + '.', '') + isnull(quotename(referenced_schema_name) + '.', '') + quotename(referenced_entity_name)) null) , not exists (select * sys.types types.name = referenced_entity_name , types.schema_id = isnull(schema_id(referenced_schema_name), schema_id('dbo')) ) order [this object...], [... depends on missing entity name] go
this script.
i tried add group [... depends on missing entity name]
following error:
invalid column name '... depends on missing entity name'.
i've tried add aggregate functions each column in result test, still same error.
group by
actual field names not alias.
select top (100) percent quotename(object_schema_name(referencing_id)) + '.' + quotename(object_name(referencing_id)) [this object...], o.type_desc, isnull(quotename(referenced_server_name) + '.', '') + isnull(quotename(referenced_database_name) + '.', '') + isnull(quotename(referenced_schema_name) + '.', '') + quotename(referenced_entity_name) [... depends on missing entity name] ,sed.referenced_class_desc ,case when o.type_desc in( 'sql_stored_procedure' ,'sql_scalar_function' ,'sql_trigger' ,'view') 'exec sys.sp_refreshsqlmodule ''' + quotename(object_schema_name(referencing_id)) + '.' + quotename(object_name(referencing_id)) + ''';' else null end [refresh sql module command] sys.sql_expression_dependencies sed left join sys.objects o on sed.referencing_id=o.object_id (is_ambiguous = 0) , (object_id(isnull(quotename(referenced_server_name) + '.', '') + isnull(quotename(referenced_database_name) + '.', '') + isnull(quotename(referenced_schema_name) + '.', '') + quotename(referenced_entity_name)) null) , not exists (select * sys.types types.name = referenced_entity_name , types.schema_id = isnull(schema_id(referenced_schema_name), schema_id('dbo')) ) group isnull(quotename(referenced_server_name) + '.', '') + isnull(quotename(referenced_database_name) + '.', '') + isnull(quotename(referenced_schema_name) + '.', '') + quotename(referenced_entity_name) order [this object...], [... depends on missing entity name] go
Comments
Post a Comment