Hello RJ,
Thanks for posting your question in the Microsoft Q&A forum.
To identify unused columns in an Azure SQL Database, you can use a combination of dynamic management views (DMVs) and custom queries.
Use sys.dm_db_index_usage_stats
to identify tables and indexes that haven't been accessed. This can help narrow down potentially unused columns
SELECT OBJECT_NAME(i.object_id) AS TableName,
i.name AS IndexName,
u.user_seeks, u.user_scans, u.user_lookups, u.user_updates
FROM sys.indexes i
LEFT JOIN sys.dm_db_index_usage_stats u
ON i.object_id = u.object_id AND i.index_id = u.index_id
WHERE OBJECTPROPERTY(i.object_id, 'IsUserTable') = 1
ORDER BY u.user_seeks + u.user_scans + u.user_lookups DESC;
Create a query to check for NULL or empty values in varchar/nvarchar columns
SELECT
t.name AS TableName,
c.name AS ColumnName,
c.max_length,
c.precision,
c.scale,
c.is_nullable,
(SELECT COUNT(*) FROM [TableName] WHERE [ColumnName] IS NULL OR [ColumnName] = '') AS EmptyCount,
(SELECT COUNT(*) FROM [TableName]) AS TotalCount
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE t.is_ms_shipped = 0
ORDER BY t.name, c.column_id;
Query sys.sql_modules to find columns referenced in SPs and views
SELECT DISTINCT
o.name AS ObjectName,
c.name AS ColumnName
FROM sys.sql_modules m
INNER JOIN sys.objects o ON m.object_id = o.object_id
CROSS APPLY sys.dm_sql_referenced_entities(o.schema_name + '.' + o.name, 'OBJECT') r
INNER JOIN sys.columns c ON r.referenced_id = c.object_id AND r.referenced_minor_id = c.column_id
WHERE o.type IN ('P', 'V') -- Stored Procedures and Views
ORDER BY o.name, c.name;
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful