-- 客户表增加微信 UnionID(可重复执行;禁止 UNIQUE) -- 用途:微信扫码/授权注册与绑定落库 UnionID,便于开放平台下跨应用识别 SET @db := DATABASE(); SET @exists := ( SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_customer' AND COLUMN_NAME = 'WechatUnionid' ); SET @sql := IF( @exists = 0, 'ALTER TABLE `t_customer` ADD COLUMN `WechatUnionid` VARCHAR(64) NULL COMMENT ''微信UnionID(开放平台)'' AFTER `WechatOpenid`', 'SELECT ''t_customer.WechatUnionid already exists'' AS info' ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET @idx_exists := ( SELECT COUNT(1) FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 't_customer' AND INDEX_NAME = 'ix_cus_wechat_unionid' ); SET @sql := IF( @idx_exists = 0, 'ALTER TABLE `t_customer` ADD KEY `ix_cus_wechat_unionid` (`WechatUnionid`)', 'SELECT ''ix_cus_wechat_unionid already exists'' AS info' ); PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;