SET NAMES utf8mb4;

DELETE t FROM basic_attachment t where t.school_id = #{schoolId};
DELETE t FROM basic_campus t where t.school_id = #{schoolId};
DELETE t FROM basic_card_rule t where t.school_id = #{schoolId};
DELETE t FROM basic_clazz t where t.school_id = #{schoolId};
DELETE t FROM basic_college t where t.school_id = #{schoolId};
DELETE t FROM basic_course t where t.school_id = #{schoolId};
DELETE t FROM t_c_statistics_temp t where exists(select temp.* from(select be.id from basic_exam be where be.school_id = #{schoolId}) temp where t.exam_id = temp.id);
DELETE t FROM t_c_statistics t where exists(select temp.* from(select be.id from basic_exam be where be.school_id = #{schoolId}) temp where t.exam_id = temp.id);
delete from mark_arbitrate_history where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_document where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_group where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_group_student where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_header_subjective_score where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_header_tag where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_header_track where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_paper where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_paper_package where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_problem_history where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_question where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_special_tag where task_id in (select id from mark_task where exam_id in (select id from basic_exam where school_id = #{schoolId}));
delete from mark_student where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_subjective_score where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_task where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_track where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_user_class where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from mark_user_group where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_answer_card where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_answer_card_subject where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_batch_paper where batch_id in (select id from scan_batch where exam_id in (select id from basic_exam where school_id = #{schoolId}));
delete from scan_batch where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_file_property where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_omr_task where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_package where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_paper_page where paper_id in (select id from scan_paper where exam_id in (select id from basic_exam where school_id = #{schoolId}));
delete from scan_student_paper where paper_id in (select id from scan_paper where exam_id in (select id from basic_exam where school_id = #{schoolId}));
delete from scan_paper where exam_id in (select id from basic_exam where school_id = #{schoolId});
delete from scan_refix_batch where exam_id in (select id from basic_exam where school_id = #{schoolId});
DELETE t FROM basic_exam t where t.school_id = #{schoolId};
DELETE t FROM basic_exam_rule t where t.school_id = #{schoolId};
DELETE t FROM basic_major t where t.school_id = #{schoolId};
DELETE t FROM basic_message t where t.school_id = #{schoolId};
DELETE t FROM basic_operation_log t where t.school_id = #{schoolId};
DELETE t FROM basic_print_config t where t.school_id = #{schoolId};
DELETE t FROM basic_semester t where t.school_id = #{schoolId};
DELETE t FROM basic_teach_course t where t.school_id = #{schoolId};
DELETE t FROM basic_student t where t.school_id = #{schoolId};
DELETE t FROM basic_template t where t.school_id = #{schoolId};
DELETE t FROM basic_teach_clazz t where t.school_id = #{schoolId};
DELETE t FROM basic_exam_student t where t.school_id = #{schoolId};
DELETE t FROM basic_user_course t where t.school_id = #{schoolId};
DELETE t FROM basic_verify_code t where t.school_id = #{schoolId};
DELETE t FROM basic_role_data_permission t where t.school_id = #{schoolId};

DELETE t FROM client_print_data t where t.school_id = #{schoolId};
DELETE t FROM client_status t where t.school_id = #{schoolId};

DELETE t FROM course_target t where t.school_id = #{schoolId};
DELETE t FROM course_evaluation t where t.school_id = #{schoolId};
DELETE t FROM course_weight t where t.school_id = #{schoolId};
DELETE t FROM course_dimension t where t.school_id = #{schoolId};

DELETE t FROM exam_card t where t.school_id = #{schoolId};
DELETE t FROM exam_detail t where t.school_id = #{schoolId};
DELETE t FROM exam_detail_course t where t.school_id = #{schoolId};
DELETE t FROM exam_print_plan t where t.school_id = #{schoolId};
DELETE t FROM exam_student t where t.school_id = #{schoolId};
DELETE t FROM exam_task t where t.school_id = #{schoolId};
DELETE t FROM exam_task_assign_paper_type t where t.exam_id in (select id from basic_exam where school_id = #{schoolId});
DELETE t FROM exam_task_paper_data t where exam_id in (select id from basic_exam where school_id = #{schoolId});
DELETE t FROM exam_task_apply_temp t where t.school_id = #{schoolId};
DELETE t FROM exam_task_detail t where exists(select temp.* from(select et.id from exam_task et where et.school_id = #{schoolId}) temp where t.exam_task_id = temp.id);
DELETE t FROM exam_task_paper_log t where exists(select temp.* from(select et.id from exam_task et where et.school_id = #{schoolId}) temp where t.exam_task_id = temp.id);
DELETE t FROM exam_task_print t where t.school_id = #{schoolId};
DELETE t FROM exam_task_review_log t where exists(select temp.* from(select et.id from exam_task et where et.school_id = #{schoolId}) temp where t.exam_task_id = temp.id);
DELETE t FROM exam_task_temp t where t.school_id = #{schoolId};

DELETE t FROM grade_batch_student t where exists(select temp.* from(select gb.id from grade_batch gb where gb.school_id = #{schoolId}) temp where t.batch_id = temp.id);
DELETE t FROM grade_batch_student_clazz t where exists(select temp.* from(select gb.id from grade_batch gb where gb.school_id = #{schoolId}) temp where t.batch_id = temp.id);
DELETE t FROM grade_batch t where t.school_id = #{schoolId};
DELETE t FROM grade_batch_paper t where t.school_id = #{schoolId};
DELETE t FROM grade_module_define t where t.school_id = #{schoolId};
DELETE t FROM grade_module_evaluation t where t.school_id = #{schoolId};
DELETE t FROM grade_paper t where t.school_id = #{schoolId};
DELETE t FROM grade_paper_dimension t where t.school_id = #{schoolId};
DELETE t FROM grade_paper_struct t where t.school_id = #{schoolId};

DELETE t FROM sys_config t where t.school_id = #{schoolId};
DELETE t FROM sys_org t where t.school_id = #{schoolId} and (t.`type` <> 'SCHOOL' or t.`type` is null);
DELETE t FROM sys_role_group_member t where exists(select temp.* from(select sr.id from sys_role sr where sr.school_id = #{schoolId}) temp where t.role_id = temp.id);
DELETE t FROM sys_role_privilege t where t.school_id = #{schoolId};
DELETE t FROM sys_user_role t where exists(select temp.* from(select sr.id from sys_role sr where sr.school_id = #{schoolId}) temp where t.role_id = temp.id);
DELETE t FROM sys_role t where t.school_id = #{schoolId};
DELETE t FROM sys_user t where t.school_id = #{schoolId};

DELETE t FROM t_b_session t where t.school_id = #{schoolId};
DELETE t FROM t_b_sync_task t where t.school_id = #{schoolId};
DELETE t FROM t_b_task t where t.school_id = #{schoolId};
DELETE t FROM t_b_task_pdf t where t.school_id = #{schoolId};
DELETE t FROM t_c_paper_struct t where exam_id in (select id from basic_exam where school_id = #{schoolId});
DELETE t FROM t_c_final_score t where exam_id in (select id from basic_exam where school_id = #{schoolId});
DELETE t FROM t_c_usual_score t where exam_id in (select id from basic_exam where school_id = #{schoolId});
DELETE t FROM t_f_flow_join t where exists(select temp.* from (select tffe.id from t_f_custom_flow_entity tffe join t_f_custom_flow tfcf on tfcf.id = tffe.t_f_custom_flow_id where tfcf.school_id = #{schoolId}) temp where t.flow_entity_id = temp.id);
DELETE t FROM t_f_custom_flow_entity t where exists(select temp.* from(select tfcf.id from t_f_custom_flow tfcf where tfcf.school_id = #{schoolId}) temp where t.t_f_custom_flow_id = temp.id);
DELETE t FROM t_f_custom_flow t where t.school_id = #{schoolId};
DELETE t FROM t_f_flow_approve t where t.school_id = #{schoolId};
DELETE t FROM t_f_flow_log t where t.school_id = #{schoolId};
DELETE t FROM t_g_error t where t.school_id = #{schoolId};
DELETE t FROM t_m_mq_message t where t.school_id = #{schoolId};
DELETE t FROM t_r_exam_student t where t.r_basic_info_id in (select id from t_r_basic_info t where exam_id in (select id from basic_exam where school_id = #{schoolId}));
DELETE t FROM t_r_basic_info t where exam_id in (select id from basic_exam where school_id = #{schoolId});
DELETE t FROM t_s_auth t where t.school_id = #{schoolId};
DELETE t FROM t_school_privilege t where t.school_id = #{schoolId};
DELETE t FROM t_school_role t where t.school_id = #{schoolId};
DELETE t FROM t_sync_exam_student_score t where t.school_id = #{schoolId};

DELETE t FROM teach_clazz t where t.school_id = #{schoolId};
DELETE t FROM teach_course t where t.school_id = #{schoolId};
DELETE t FROM teach_student t where t.school_id = #{schoolId};