Mysql implements if judgment statements without using stored procedures

< H1 > achieve the goal: < / H1 >

determines whether the field exists, and if so, does not change it.
if the field does not exist, execute the new field source the default value is null , and the existing field source is set to 0

< H2 > the existing code is as follows < / H2 >
IF NOT EXITS (SELECT * FROM information_schema.columns where table_schema = DATABASE()  AND table_name = "file" AND column_name = "source") THEN
    Alter table file add source varchar(20);
    Update file set source = "0";
END IF;
Mar.23,2021
Menu