Voici un petit script SQL qui donne une table contenant toutes les colonnes vide de toutes les tables de la base.
CREATE TABLE ##COLVIDE (NOM_TABLE NVARCHAR(257), COLONNE NVARCHAR(128));
DECLARE @T TABLE (N INT IDENTITY, COMMANDE NVARCHAR(max))
DECLARE @N INT, @SQL NVARCHAR(max);
INSERT INTO @T
SELECT 'IF NOT EXISTS(SELECT [' + COLUMN_NAME + '] ' +
'FROM [' + C.TABLE_SCHEMA +'].[' + C.TABLE_NAME +'] '+
'WHERE ['+ COLUMN_NAME + '] IS NOT NULL) ' +
'INSERT INTO ##COLVIDE ' +
'VALUES (''' + C.TABLE_SCHEMA +'.' + C.TABLE_NAME + ''', ''' + COLUMN_NAME + ''')'
FROM INFORMATION_SCHEMA.COLUMNS AS C
INNER JOIN INFORMATION_SCHEMA.TABLES AS T
ON C.TABLE_SCHEMA = T.TABLE_SCHEMA
AND C.TABLE_NAME = T.TABLE_NAME
WHERE TABLE_TYPE = 'BASE TABLE';
WHILE EXISTS(SELECT * FROM @T)
BEGIN
SELECT TOP 1 @N = N, @SQL = COMMANDE FROM @T;
EXEC (@SQL);
DELETE FROM @T WHERE N = @N;
END;
SELECT * FROM ##COLVIDE ;
DROP TABLE ##COLVIDE;
--------
Frédéric Brouard, SQLpro - ARCHITECTE DE DONNÉES, http://sqlpro.developpez.com/
Expert bases de données relationnelles et langage SQL. MVP Microsoft SQL Server
www.sqlspot.com : modélisation, conseil, audit, optimisation, tuning, formation
* * * * * Enseignant CNAM PACA - ISEN Toulon - CESI Aix en Provence * * * * *