-- ============================================
-- 删除 user_id >= 100 的用户及其关联数据
-- 只删除：用户、学习记录、语音评测、课程分配
-- 保留：admin(1), ry(2) 等系统用户
-- 执行前请先备份数据库！
-- ============================================

-- 关闭外键检查（加快删除速度）
SET FOREIGN_KEY_CHECKS = 0;

-- ============================================
-- 1. 删除学习记录
-- ============================================

-- 删除学习详情记录
DELETE FROM learning_detail WHERE student_id >= 100;

-- 删除学习记录
DELETE FROM learning_record WHERE student_id >= 100;

-- ============================================
-- 2. 删除语音评测记录
-- ============================================

DELETE FROM voice_evaluation WHERE student_id >= 100;

-- ============================================
-- 3. 删除课程分配（只删除该用户的分配，不影响课程本身）
-- ============================================

DELETE FROM course_assignment WHERE student_id >= 100;

-- ============================================
-- 4. 删除用户
-- ============================================

DELETE FROM sys_user WHERE user_id >= 100;

-- 恢复外键检查
SET FOREIGN_KEY_CHECKS = 1;

-- ============================================
-- 验证结果
-- ============================================

-- 查看剩余用户数量
SELECT COUNT(*) AS '剩余用户数' FROM sys_user;

-- 查看剩余用户列表
SELECT user_id, user_name, nick_name FROM sys_user ORDER BY user_id;

-- 确认课件未受影响
SELECT COUNT(*) AS '课件数量' FROM courseware;
SELECT COUNT(*) AS '课程数量' FROM course;
SELECT COUNT(*) AS '评测内容数量' FROM voice_evaluation_content;
