简体   繁体   中英

Alter table add column and set default value in MySQL

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.

SET不是必需的:

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

try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM