Skip to content

Instantly share code, notes, and snippets.

@matt40k
Created December 22, 2015 14:53
Show Gist options
  • Save matt40k/431f289e473c259aa235 to your computer and use it in GitHub Desktop.
Save matt40k/431f289e473c259aa235 to your computer and use it in GitHub Desktop.
Lists all the tables that are missing descriptions on the audit columns
select
SchemaName = schema_name(t.schema_id)
,TableName = t.name
from
sys.tables t
left outer join (
select
SchemaName
,TableName
from
(
select
SchemaName
,TableName
,object_id
,ETL_Run_ID = max(ETL_Run_ID)
,ETL_Created_Date = max(ETL_Created_Date)
,ETL_Created_By = max(ETL_Created_By)
from
(
select
SchemaName = schema_name(t.schema_id)
,TableName = t.name
,object_id = t.object_id
,'ETL_Run_ID' = case when c.name = 'ETL_Run_ID' then c.column_id else null end
,'ETL_Created_Date' = case when c.name = 'ETL_Created_Date' then c.column_id else null end
,'ETL_Created_By' = case when c.name = 'ETL_Created_By' then c.column_id else null end
from
sys.tables t
inner join sys.columns c on
t.object_id = c.object_id
inner join sys.types types on
c.system_type_id = types.system_type_id
and types.name NOT IN ('xml')
and c.name in ('ETL_Run_ID', 'ETL_Created_Date', 'ETL_Created_By')
where
schema_name(t.schema_id) not in ('Audit')
) q
group by
q.SchemaName
,q.TableName
,q.object_id
) q
left outer join sys.extended_properties runId on
q.object_id = runId.major_id
and q.ETL_Run_ID = runId.minor_id
and runId.name = 'MS_Description'
left outer join sys.extended_properties createDt on
q.object_id = createDt.major_id
and q.ETL_Created_Date = createDt.minor_id
and createDt.name = 'MS_Description'
left outer join sys.extended_properties createBy on
q.object_id = createBy.major_id
and q.ETL_Created_By = createBy.minor_id
and createBy.name = 'MS_Description'
where
runId.value is null
or createDt.value is null
or createBy.value is null
) q on
schema_name(t.schema_id) = q.SchemaName
and t.name = q.TableName
where
q.TableName is not null
and schema_name(t.schema_id) not in ('Audit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment