Is there a way, via a SQL statement, to ensure a column's default value is an empty string ''
instead of NULL
?
Asked
Active
Viewed 7.3k times
49

p.campbell
- 98,673
- 67
- 256
- 322

Sharpeye500
- 8,775
- 25
- 95
- 143
1 Answers
73
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;

OMG Ponies
- 325,700
- 82
- 523
- 502
-
Could you use SPACE(0) in a VARCHAR or NVARCHAR column? – Jul 28 '10 at 22:11
-
1@Randolph Potter: [SPACE()](http://msdn.microsoft.com/en-us/library/ms187950.aspx) is a TSQL/SQL Server function - so "No" for MySQL. – OMG Ponies Jul 28 '10 at 22:12