50

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

p.campbell
101k70 gold badges262 silver badges326 bronze badges
asked Jul 28, 2010 at 22:08

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;
answered Jul 28, 2010 at 22:10

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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.