Last active
January 31, 2018 00:47
-
-
Save vardius/734ab1c756793ef5def4d6963c23fb34 to your computer and use it in GitHub Desktop.
Display all table/column names where value is a specific string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
DROP PROCEDURE IF EXISTS `displayNullColumns`$$ | |
CREATE PROCEDURE `displayNullColumns`() | |
BEGIN | |
SET @expression = ( | |
SELECT GROUP_CONCAT(CONCAT('SELECT ', s._column, ' AS _value, \'', s._column, '\' AS _column, \'', s._table, '\' AS _table FROM ', s._table, ' WHERE ', s._column, ' = \'null\'') | |
SEPARATOR ' UNION ') | |
FROM ( | |
SELECT DISTINCT | |
COLUMN_NAME AS `_column`, | |
TABLE_NAME AS `_table` | |
FROM INFORMATION_SCHEMA.COLUMNS | |
WHERE TABLE_SCHEMA = 'dev_table' | |
AND COLUMN_NAME IS NOT NULL | |
AND TABLE_NAME IS NOT NULL | |
) AS s | |
); | |
IF @expression IS NOT NULL AND @expression != '' | |
THEN | |
PREPARE stmt FROM @expression; | |
EXECUTE stmt; | |
END IF; | |
END$$ | |
DELIMITER ; | |
CALL displayNullColumns(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment