Is there a way, via a SQL statement, to ensure a column's default value is an empty string ''
instead of NULL
?
views:
34answers:
1
+4
A:
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
2010-07-28 22:10:27
Could you use SPACE(0) in a VARCHAR or NVARCHAR column?
Randolph Potter
2010-07-28 22:11:27
@Randolph Potter: [SPACE()](http://msdn.microsoft.com/en-us/library/ms187950.aspx) is a TSQL/SQL Server function - so "No" for MySQL.
OMG Ponies
2010-07-28 22:12:54
Thanks OMG Ponies, works great.
Sharpeye500
2010-07-28 22:16:00
does it work good enough to mark it as the 'answer'? :-)
dave
2010-07-28 22:19:11
@OMG - Thanks, makes sense.
Randolph Potter
2010-07-28 23:37:30