nick cruse
nick cruse

Reputation: 141

Alter mysql table default value and NULLvalue?

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`

Upvotes: 0

Views: 41

Answers (2)

vinz
vinz

Reputation: 566

ALTER TABLE `table_name` ADD `test` INT NOT NULL AFTER `test1`;

Upvotes: 1

Kibadachi
Kibadachi

Reputation: 175

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

Upvotes: 1

Related Questions