如何在MySQL中一次更新所有列

时间:2019-07-06 10:36:25

标签: mysql sql

有一个包含200列的数据库,如何以这种方式将数据从21更新为200-

Set Column21 = NEW.Column21, 
    Column22 = NEW.Column22, 
    Column23 = NEW.Column23,
    Column24 = NEW.Column24,
    Column25 = NEW.Column25...

1 个答案:

答案 0 :(得分:0)

//You can loop through 22 to  200 and make the string or access property

let sql = "Set",i=22;
 [...Array(179)].forEach((_, l) => {

    let column = 'Column'+i;
    let val  = "some val"; //access value
    sql += ` ${column} = ${val} `;
    i++;
});
console.log(sql);