0

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
1
  • 1
    An integer column cannot have 'none' as default value, since 'none' is a string. Commented Jul 23, 2015 at 14:55

2 Answers 2

1
ALTER TABLE `table_name` ADD `test` INT NOT NULL AFTER `test1`;
answered Jul 23, 2015 at 14:55

Comments

1
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

answered Jul 23, 2015 at 14:53

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.