How can i make a table field with default value "none" and null value "no"?
When i create a table with following code it always add default value NULL and null to yes
ALTER TABLE `table_name` ADD `test` INT(11) AFTER `test1`
Your Common Sense
158k42 gold badges226 silver badges371 bronze badges
asked Jul 22, 2015 at 18:18
-
1An integer column cannot have 'none' as default value, since 'none' is a string.Lorenz Meyer– Lorenz Meyer2015年07月23日 14:55:10 +00:00Commented Jul 23, 2015 at 14:55
2 Answers 2
ALTER TABLE `table_name` ADD `test` INT NOT NULL AFTER `test1`;
Comments
ALTER TABLE myTable
ALTER column SET DEFAULT 'none'.
For replacing NULL with NO you don't have to alter the table just do it in your query :
SELECT COALESCE(columnWhichisNull,'no'))
FROM myTable ;
COALESCE
checks if a value from a column is null and replaces it with your desired character
Comments
lang-sql