patternsqlModerate
MYSQL only Show columns which allow null
Viewed 0 times
showcolumnsnullallowmysqlwhichonly
Problem
I need to be able to pull the column names which allow a NULL value, I know that
Will give show me the table properties and whether or not the column allows null values, but is there a way to just return ONLY the columnnames which allow null.
And of course it's easy to just pull everything and sort it out later on, but if there IS a way to do what I'm asking, I'd like to learn it.
show columns from TABLEWill give show me the table properties and whether or not the column allows null values, but is there a way to just return ONLY the columnnames which allow null.
show columns from TABLE where Null = 'YES' doesn't work, but it explains what I need to accomplish. And of course it's easy to just pull everything and sort it out later on, but if there IS a way to do what I'm asking, I'd like to learn it.
Solution
Yes you can do it by using the information_schema database..
use the Query
use the Query
SELECT COLUMN_NAME
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA='db name'
AND TABLE_NAME='table Name'
AND IS_NULLABLE='YES';Code Snippets
SELECT COLUMN_NAME
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA='db name'
AND TABLE_NAME='table Name'
AND IS_NULLABLE='YES';Context
StackExchange Database Administrators Q#19111, answer score: 10
Revisions (0)
No revisions yet.