default a column with empty string

Sharpeye500 picture Sharpeye500 · Jul 29, 2010 · Viewed 68.8k times · Source

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

Answer

OMG Ponies picture OMG Ponies · Jul 29, 2010

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;