-- ========================================
-- 清空指定资料的所有知识点（物理删除）
-- 用途：为Dify工作流准备，清空旧知识点以便重新生成
-- ========================================

-- 使用方法：
-- 1. 直接执行：将下面的 34 替换为实际的 material_id
-- 2. 在Dify中使用：将整个SQL复制到Dify的SQL节点中

-- ========================================
-- 方式1：删除单个资料的知识点
-- ========================================
DELETE FROM knowledge_points WHERE material_id = 34;
-- 验证删除结果
SELECT '删除完成' as status, ROW_COUNT() as deleted_count;

-- ========================================
-- 方式2：使用变量（更灵活）
-- ========================================
-- SET @material_id = 34;
-- DELETE FROM knowledge_points WHERE material_id = @material_id;
-- SELECT CONCAT('已删除资料 ', @material_id, ' 的所有知识点') as result, ROW_COUNT() as count;

-- ========================================
-- 方式3：批量删除多个资料的知识点
-- ========================================
-- DELETE FROM knowledge_points WHERE material_id IN (34, 35, 36);
-- SELECT ROW_COUNT() as total_deleted;

-- ========================================
-- 方式4：删除并验证（完整版）
-- ========================================
-- -- 查看删除前的数量
-- SELECT '删除前' as timing, COUNT(*) as count FROM knowledge_points WHERE material_id = 34;
-- 
-- -- 执行删除
-- DELETE FROM knowledge_points WHERE material_id = 34;
-- 
-- -- 查看删除后的数量（应该为0）
-- SELECT '删除后' as timing, COUNT(*) as count FROM knowledge_points WHERE material_id = 34;

-- ========================================
-- 注意事项
-- ========================================
-- 1. 这是物理删除，数据无法恢复
-- 2. 如果有错题记录引用这些知识点，会自动将 exam_mistakes.knowledge_point_id 设置为 NULL
-- 3. 删除后可以通过Dify工作流重新生成新的知识点
-- 4. 默认会自动提交事务（autocommit=1）

-- ========================================
-- 快速使用：Dify工作流SQL节点
-- ========================================
-- 复制以下单行命令到Dify的SQL执行节点：
-- DELETE FROM knowledge_points WHERE material_id = {{material_id}};

