Skip to main content

SLAM_Alpha_profile_data

Overview​

SLAM_Alpha_profile_data is a utility procedure that profiles SQL Server tables to produce comprehensive descriptive statistics at three granularities:

  • Table-level: Row counts, column counts
  • Column-level: Min/max values, averages, null counts, blank counts, distinct values
  • Value-level: Frequency distribution for low-cardinality columns

The profiling is designed for incremental processing, allowing you to profile tables selectively and avoid re-profiling unchanged data. Results are written to three output tables: profile_tables, profile_columns, and profile_values.

Note: This operation requires valid Salesforce credentials for license validation. However, the profiling itself only accesses SQL Server data.

Parameters​

NameTypeDefaultDescription
@table_matchVARCHAR(255)'%'LIKE pattern to filter tables to profile (e.g., 'Customer%' for tables starting with "Customer")
@schema_matchVARCHAR(255)'%'LIKE pattern to filter schemas (e.g., 'dbo' for only the dbo schema)
@refresh_existingBIT0Whether to re-profile tables that match the filter criteria but have been profiled before. 0 = skip already profiled tables, 1 = re-profile all matching tables
@value_limitINT50Maximum distinct values to profile for frequency distribution. Columns with more distinct values will skip value profiling. Maximum: 60

Output Tables​

The procedure writes results to three tables in the dbo schema (created automatically if they don't exist).

profile_tables​

Table-level statistics with one row per profiled table.

ColumnTypeDescription
schema_nameNVARCHAR(128)Schema name
table_nameNVARCHAR(128)Table name
qualified_nameComputedschema_name.table_name
num_rowsBIGINTTotal row count
num_columnsINTTotal column count
date_profiledDATETIME2Timestamp of profiling run

profile_columns​

Column-level statistics with one row per column in each profiled table.

ColumnTypeDescription
schema_nameNVARCHAR(128)Schema name
table_nameNVARCHAR(128)Table name
column_nameNVARCHAR(128)Column name
qualified_nameComputedschema_name.table_name.column_name
typeNVARCHAR(128)SQL Server data type
lengthINTColumn length (for string/binary types)
scaleINTColumn scale (for numeric types)
precisionINTColumn precision (for numeric types)
nullableBITWhether column allows NULLs
min_valueNVARCHAR(MAX)Minimum value (NULL for non-applicable types)
max_valueNVARCHAR(MAX)Maximum value
average_valueNVARCHAR(50)Average value (numeric types only)
max_lengthINTMaximum character/byte length (string/binary types only)
num_distinctBIGINTNumber of distinct non-NULL values (similar to SQL COUNT(DISTINCT column_name))
is_unique_non_nullBIT1 if all non-NULL values are unique and no NULLs exist
num_filledBIGINTNumber of non-NULL values (blanks count as filled)
num_nullBIGINTNumber of NULL rows
num_blankBIGINTNumber of blank rows (empty string or whitespace-only, string types only)
num_blank_or_nullBIGINTnum_null + num_blank
num_zeroBIGINTNumber of rows with value 0 (numeric) or '0' (string)
num_table_rowsBIGINTTotal table row count
percent_filledDECIMAL(5,2)Percentage of filled rows (0.00 - 100.00)
percent_nullDECIMAL(5,2)Percentage of NULL rows
percent_blankDECIMAL(5,2)Percentage of blank rows
percent_blank_or_nullDECIMAL(5,2)Percentage of blank or NULL rows
percent_zeroDECIMAL(5,2)Percentage of zero rows
date_profiledDATETIME2Timestamp of profiling run

profile_values​

Value frequency distribution for columns with low cardinality (≤ @value_limit distinct values).

ColumnTypeDescription
schema_nameNVARCHAR(128)Schema name
table_nameNVARCHAR(128)Table name
column_nameNVARCHAR(128)Column name
valueNVARCHAR(255)Distinct value (truncated to 252 chars + '...' if longer)
countBIGINTNumber of occurrences
frequencyDECIMAL(10,6)Frequency as decimal (count / num_table_rows)
date_profiledDATETIME2Timestamp of profiling run

Results are sorted by count DESC, value ASC (most frequent values first).

Usage Examples​

Profile Tables by Pattern​

Profile only tables matching a specific pattern:

-- Profile all tables starting with 'Customer'
-- e.g. Customer, CustomerAddress, CustomerOrders
EXEC dbo.SLAM_Alpha_profile_data
@table_match = 'Customer%'

-- View table summaries
SELECT * FROM dbo.profile_tables

-- View column statistics for a specific table
SELECT * FROM dbo.profile_columns
WHERE table_name = 'CustomerAddress'

Incremental Profiling​

Profile tables incrementally across multiple runs:

-- Profile tables starting with 'A'
EXEC dbo.SLAM_Alpha_profile_data @table_match = 'A%'

-- Later, profile tables starting with 'B' (doesn't re-profile 'A' tables)
EXEC dbo.SLAM_Alpha_profile_data @table_match = 'B%'

-- View all profiled tables
SELECT * FROM dbo.profile_tables ORDER BY schema_name, table_name

Refresh Existing Profiling Data​

Re-profile tables that have already been profiled:

-- Re-profile all previously profiled tables
EXEC dbo.SLAM_Alpha_profile_data @refresh_existing = 1

-- Re-profile only Customer tables
EXEC dbo.SLAM_Alpha_profile_data
@table_match = 'Customer%',
@refresh_existing = 1

Adjust Value Profiling Limit​

Profile value distributions for columns with more distinct values:

-- Profile with higher value limit (up to 60)
EXEC dbo.SLAM_Alpha_profile_data
@value_limit = 60

-- This will profile value distributions for columns with up to 60 distinct values

Complete Example with All Parameters​

-- Profile tables in dbo schema starting with 'SF_', refresh existing, max value limit
EXEC dbo.SLAM_Alpha_profile_data
@table_match = 'SF_%',
@schema_match = 'dbo',
@refresh_existing = 1,
@value_limit = 60

Data Type Handling​

Numeric Types (int, bigint, decimal, float, money, etc.)​

  • min_value, max_value, average_value: Calculated and stored as strings
  • average_value: Rounded to 2 decimal places for money types, 4 for others
  • num_zero: Count of rows where value = 0
  • max_length: NULL (not applicable)

Date/Time Types (date, datetime, datetime2, time, etc.)​

  • min_value, max_value: ISO 8601 format (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.mmm)
  • average_value: NULL (not applicable)
  • num_zero: NULL (not applicable)

String Types (char, varchar, nchar, nvarchar, text)​

  • min_value, max_value: Lexicographic ordering (case-sensitive)
  • max_length: Character count (excludes trailing spaces)
  • num_zero: Count of rows where value = '0' (string zero)
  • num_blank: Count of rows where value is empty or whitespace-only

Binary Types (binary, varbinary, image)​

  • min_value, max_value, average_value: NULL (not applicable)
  • max_length: Byte count
  • Value profiling: Skipped (no rows in profile_values)

NULL and Blank Definitions​

MetricDefinition
num_nullRows where column IS NULL (all data types)
num_blankRows where column is empty string or whitespace-only after trimming (string types only, 0 for other types)
num_blank_or_nullnum_null + num_blank
num_fillednum_table_rows - num_null (blanks count as filled)
Whitespace vs Empty String in Distinct Counts

The num_distinct value in profile_columns and the values in profile_values treat whitespace-only strings (e.g., ' ') as distinct from empty strings (''). This differs from SQL Server's COUNT(DISTINCT column_name), which treats whitespace and empty strings as equivalent values.

For example, if a column contains both '' and ' ', these are counted as 2 distinct values, while SQL's COUNT(DISTINCT) would count them as 1.

Value Profiling Rules​

  • Values are profiled only if num_distinct <= @value_limit
  • NULL values are included in value profiling with their own row
  • String values longer than 255 characters are truncated to 252 + '...'
  • Columns exceeding the value limit are skipped entirely (no rows in profile_values)