guoyu/log/数据库/fix_student_remark.sql
2025-12-11 23:28:07 +08:00

36 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 批量修复学员remark字段
-- 给所有userName以数字开头的用户添加学员标识
-- 1. 查看哪些用户会被修复
SELECT
user_id,
user_name,
nick_name,
user_type,
remark
FROM sys_user
WHERE user_name REGEXP '^[0-9]' -- userName以数字开头
AND user_id != 1 -- 排除管理员
AND (remark IS NULL OR remark NOT LIKE '%注册类型:student%');
-- 2. 执行修复(请先执行上面的查询确认无误后再执行)
UPDATE sys_user
SET remark = CONCAT(IFNULL(remark, ''), '注册类型:student')
WHERE user_name REGEXP '^[0-9]' -- userName以数字开头
AND user_id != 1 -- 排除管理员
AND (remark IS NULL OR remark NOT LIKE '%注册类型:student%');
-- 3. 验证修复结果
SELECT
user_id,
user_name,
nick_name,
remark
FROM sys_user
WHERE user_name REGEXP '^[0-9]'
AND user_id != 1;
-- 说明:
-- 本脚本会给所有userName以数字开头的用户添加"注册类型:student"标识
-- 例如110, 111, 116 等用户名会被识别为学员