1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
DECLARE @sql VARCHAR(MAX) = ''
DECLARE @Table SYSNAME
SELECT
@sql +=
CASE WHEN TABLE_NAME = @Table --colonne suivante
THEN CHAR(13) + CHAR(9) + CHAR(9) + 'AND ' + TABLE_NAME + '.' + COLUMN_NAME + ' = T2.' + COLUMN_NAME
ELSE --table suivante
CASE WHEN @sql = ''
THEN '' --premiere table
ELSE ');' + CHAR(13) + CHAR(13) --table suivante : on termine la requete precedente, et on passe à la suivante...
END
+ 'DELETE FROM ' + TABLE_NAME + CHAR(13)
+ 'WHERE ' + COLUMN_NAME + ' > ANY ( '
+ CHAR(13) + CHAR(9) + 'SELECT ' + COLUMN_NAME
+ CHAR(13) + CHAR(9) + 'FROM ' + TABLE_NAME + ' T2 '
+ CHAR(13) + CHAR(9) + 'WHERE ' + TABLE_NAME + '.' + COLUMN_NAME + ' <> T2.' + COLUMN_NAME
END,
@Table = TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
ORDER BY TABLE_NAME, ORDINAL_POSITION
PRINT @sql |
Partager