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
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
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.