How to set multiple default constraint to multiple columns at once in MySQL?

362 Views Asked by At

Is there a way to alter table to set multiple default constraints at once in MySQL?

This is what I tried

ALTER TABLE test00.tbl_00 ALTER card_flg_visa,card_flg_jcb SET DEFAULT (0, 1);

The following error occured

Error Code: 1064. 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 ', card_flg_jcb SET DEFAULT (0, 1)' at line 1

1

There are 1 best solutions below

0
Nick On

You can write this as one query but you have to alter each column separately:

ALTER TABLE test00.tbl_00 
    ALTER card_flg_visa SET DEFAULT 0,
    ALTER card_flg_jcb SET DEFAULT 1;

Demo on dbfiddle