50

Is there a way, via a SQL statement, to ensure a column's default value is an empty string '' instead of NULL?

1 Answer 1

74

Yes - use a DEFAULT constraint:

DROP TABLE IF EXISTS `example`.`test`;
CREATE TABLE  `example`.`test` (
  `string_test` varchar(45) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Sign up to request clarification or add additional context in comments.

2 Comments

Could you use SPACE(0) in a VARCHAR or NVARCHAR column?
@Randolph Potter: SPACE() is a TSQL/SQL Server function - so "No" for MySQL.

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.