Setting a column's default value by adding a constraint I wrote this query:

ALTER TABLE test2 add constraint setting_value33 default male FOR namee;


But I get this error when running it:


  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'default male FOR namee' at line 1
This is a rather contrived example, but you'll get the idea.

mysql&gt; create table b(a int primary key, c varchar(3), unique key x_b_uk (c));
Query OK, 0 rows affected (0.46 sec)

mysql&gt; alter table b alter c set default 'xyz';
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql&gt; insert into b (a) values(1);   &lt;&lt;== didn't set field c!
Query OK, 1 row affected (0.39 sec)

mysql&gt; select * from b;
+---+------+
| a | c    |
+---+------+
| 1 | xyz  |                    &lt;&lt;===== value of c = 'xyz'!
+---+------+
1 row in set (0.16 sec)

mysql&gt; 


Check here.