Set column default value for VARCHAR : Char Varchar « Data Types « MySQL Tutorial






mysql>
mysql> CREATE TABLE myTable
    -> (
    ->    ID SMALLINT UNSIGNED NOT NULL,
    ->    Year YEAR NOT NULL,
    ->    City VARCHAR(40) NOT NULL DEFAULT 'Unknown'
    -> )
    -> ENGINE=INNODB;
Query OK, 0 rows affected (0.08 sec)

mysql>
mysql> desc myTable;
+-------+----------------------+------+-----+---------+-------+
| Field | Type                 | Null | Key | Default | Extra |
+-------+----------------------+------+-----+---------+-------+
| ID    | smallint(5) unsigned | NO   |     |         |       |
| Year  | year(4)              | NO   |     |         |       |
| City  | varchar(40)          | NO   |     | Unknown |       |
+-------+----------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

mysql>
mysql> drop table myTable;
Query OK, 0 rows affected (0.03 sec)








10.5.Char Varchar
10.5.1.CHAR and VARCHAR
10.5.2.Differences between CHAR and VARCHAR
10.5.3.Set column default value for VARCHAR
10.5.4.VARCHAR column with default value
10.5.5.All CHAR and VARCHAR values in MySQL are compared without regard to any trailing spaces
10.5.6.If a given value is stored into the CHAR(4) and VARCHAR(4) columns, the trailing spaces of values retrieved from the columns are removed from CHAR columns.