-- 存量库:SKU / 订单申报增加「出口申报要素」DeclareElement -- 可重复执行;仅在列不存在时 ADD。 SET @db := DATABASE(); -- c_sku.DeclareElement SET @exists := ( SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'c_sku' AND COLUMN_NAME = 'DeclareElement' ); SET @sql := IF( @exists = 0, 'ALTER TABLE `c_sku` ADD COLUMN `DeclareElement` VARCHAR(255) NULL COMMENT ''出口申报要素'' AFTER `ImHsCode`', 'SELECT ''c_sku.DeclareElement already exists'' AS info' ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; -- t_order_declaration.DeclareElement SET @exists := ( SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_order_declaration' AND COLUMN_NAME = 'DeclareElement' ); SET @sql := IF( @exists = 0, 'ALTER TABLE `t_order_declaration` ADD COLUMN `DeclareElement` VARCHAR(255) NULL COMMENT ''出口申报要素'' AFTER `ExHsCode`', 'SELECT ''t_order_declaration.DeclareElement already exists'' AS info' ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;