/sp_GetColumnMetadataStats

SQL Server Stored Procedure to get table or view column metadata and statistics

Primary LanguageTSQLGNU General Public License v3.0GPL-3.0

sp_GetColumnMetadataStats

SQL Server Stored Procedure to get table or view column metadata and statistics

USE [DBA]
GO

DECLARE @RC int
      , @DatabaseName sysname
      , @SchemaName sysname
      , @TableName sysname
      , @IncludeStats bit
      , @IncludeTopValues bit
      , @Debug bit

SET @DatabaseName = N'AdventureWorksDW2019';
SET @SchemaName = N'dbo';
SET @TableName = N'DimProduct';
SET @IncludeStats = 0;
SET @IncludeTopValues = 0;

EXECUTE @RC = [dbo].[sp_GetColumnMetadataStats] 
   @DatabaseName
  ,@SchemaName
  ,@TableName
  ,@IncludeStats
  ,@IncludeTopValues
  ,@Debug
GO

image

IncludeStats

Setting this flag add the following additional statistics columns to the output

count_distinct count_empty count_null count_row val_min val_max len_max

image

IncludeTopValues

This flag adds top 10 values for each column ordered in descending order, with the count shown in parenthesis after each item.

The @IncludeStats flag must also be set.

image