How do I get a list of all column names in a table that do not have NULL as their default value?
If I do "SHOW COLUMNS FROM table_name", I see there is a column in the results called "Default". I'd like my statement to return ONLY those columns that do not have NULL as the Default. I've tried using a WHERE clause, but I think it chokes because "Default" is a reserved word.
Thanks for any help!
You can query a INFORMATION_SCHEMA.COLUMNS table:
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'my_table'
AND column_default is [not] null;
Your title says "have null as their default" but post say "do not have null as their default". Pick one :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With