Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default a column with empty string

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

like image 418
Sharpeye500 Avatar asked Jul 28 '10 22:07

Sharpeye500


People also ask

How do I set a DEFAULT column value?

In Object Explorer, right-click the table with columns for which you want to change the scale and select Design. Select the column for which you want to specify a default value. In the Column Properties tab, enter the new default value in the Default Value or Binding property.

Can we alter column with default value?

You cannot alter a column to specify a default value if one of the following conditions exists: The table is referenced by a view.

What is a DEFAULT column?

Certain columns and data types have predefined or assigned default values. For example, default column values for the various data types are as follows: NULL. 0 Used for small integer, integer, decimal, single-precision floating point, double-precision floating point, and decimal floating point data type.

What is the default value of a column?

Default values can be NULL, or they can be a value that matches the data type of the column (number, text, date, for example).


1 Answers

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; 
like image 92
OMG Ponies Avatar answered Sep 23 '22 13:09

OMG Ponies