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`
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`;
Sign up to request clarification or add additional context in comments.

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

Comments

Your Answer

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.