4

Is there a way to add a new column and set its default value in MySQL? When I run this command I get a syntax error:

ALTER TABLE tableName ADD newColumn varchar(20) SET DEFAULT 'test';

The documentation I've found doesn't really help me.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Omega Cat
  • 41
  • 1
  • 1
  • 2

2 Answers2

7

The SET shouldn't be necessary:

ALTER TABLE tableName ADD newColumn varchar(20) DEFAULT 'test';
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
-1

try this

ALTER TABLE tableName ADD COLUMN newColumn VARCHAR(20) DEFAULT 'test';