Get a list of all column names in a table that are not NULL as the default?

How to get a list of all column names in a table that are not NULL as the default value?

If I do "SHOW COLUMNS FROM table_name", I see that there is a column in the results called "Default". I would like my operator to return ONLY those columns that are not NULL as the default value. I tried using the WHERE clause, but I think it is suffocating because "Default" is a reserved word.

Thanks for any help!

+6
mysql
source share
1 answer

You can query the table INFORMATION_SCHEMA.COLUMNS :

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'my_table' AND column_default is [not] null; 

Your name says: "is null as the default," but post say "do not have null as the default." Choose one :-)

+14
source share

All Articles