How to find Null values without specifying attribute (MariaDB)

0

I would like to do a search to find NULL values across the table without having to determine which of the attributes might have NULL.

NOTE: with ALL the table I mean that somewhere in it has null, not that the table should be composed entirely of null elements. OK?

Thank you in advance

    
asked by anonymous 04.07.2016 / 00:00

1 answer

2

Lucas, to perform the procedure you want a lot of manual work is required (or a stored procedure, which a little runs out of MySQL knowledge).

For this you can follow the following steps:

1) Run the following select by changing the table name (your_table) to find out which columns can receive null values in the table you want.

SELECT GROUP_CONCAT(column_name) FROM information_schema.columns WHERE table_name = 'sua_tabela' AND IS_NULLABLE = 'YES';

Once this is done, replace "columns ..." with the result of the first select and rename "your_table". You must now add an OR (OR) condition for each column you select, followed by the IS NULL condition, as shown below:

SELECT colunas... FROM sua_tabela
WHERE coluna1 IS NULL 
OR coluna2 IS NULL
or colunaN... IS NULL

This is not a difficult job, but the more columns there are, and the more repetitive this more tiring work will be, so if you need to do this routinely I advise you to study MySQL stored procedures so that you can implement this routine that I passed in an automated way.

I hope I have helped you.

    
04.07.2016 / 00:31