183 lines
18 KiB
SQL
183 lines
18 KiB
SQL
-- ==========================================
|
|
-- 学生信息表字段完整性检查脚本
|
|
-- 版本:V2.3.0
|
|
-- 功能:检查实体类所有字段是否在数据库表中存在
|
|
-- 作者:Cursor AI 辅助
|
|
-- 时间:2025-01-12
|
|
-- 目的:彻底解决字段缺失问题,确保100%匹配
|
|
-- ==========================================
|
|
|
|
-- 设置字符集
|
|
SET NAMES utf8mb4;
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
-- ----------------------------
|
|
-- 检查XgStudentInfo实体类所有字段
|
|
-- ----------------------------
|
|
|
|
SELECT '==============================' as 'Result';
|
|
SELECT '🔍 学生信息表字段完整性检查' as 'Result';
|
|
SELECT '==============================' as 'Result';
|
|
|
|
-- 检查所有实体类字段是否存在(按实体类顺序)
|
|
SELECT '=== XgStudentInfo 实体类字段检查 ===' as 'Result';
|
|
|
|
-- 基础字段检查
|
|
SELECT
|
|
'id' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'id'
|
|
|
|
UNION ALL SELECT 'student_no' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'student_no'
|
|
|
|
UNION ALL SELECT 'id_card' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'id_card'
|
|
|
|
UNION ALL SELECT 'name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'name'
|
|
|
|
UNION ALL SELECT 'name_pinyin' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'name_pinyin'
|
|
|
|
UNION ALL SELECT 'gender' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'gender'
|
|
|
|
UNION ALL SELECT 'birth_date' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'birth_date'
|
|
|
|
UNION ALL SELECT 'nation' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'nation'
|
|
|
|
UNION ALL SELECT 'political_status' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'political_status'
|
|
|
|
UNION ALL SELECT 'student_status' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'student_status'
|
|
|
|
UNION ALL SELECT 'enrollment_year' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'enrollment_year'
|
|
|
|
UNION ALL SELECT 'enrollment_date' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'enrollment_date'
|
|
|
|
UNION ALL SELECT 'school_system' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'school_system'
|
|
|
|
UNION ALL SELECT 'education_level' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'education_level'
|
|
|
|
UNION ALL SELECT 'training_type' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'training_type'
|
|
|
|
UNION ALL SELECT 'major_code' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'major_code'
|
|
|
|
UNION ALL SELECT 'major_name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'major_name'
|
|
|
|
UNION ALL SELECT 'class_code' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'class_code'
|
|
|
|
UNION ALL SELECT 'class_name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'class_name'
|
|
|
|
UNION ALL SELECT 'college_code' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'college_code'
|
|
|
|
UNION ALL SELECT 'college_name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'college_name'
|
|
|
|
UNION ALL SELECT 'phone' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'phone'
|
|
|
|
UNION ALL SELECT 'email' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'email'
|
|
|
|
UNION ALL SELECT 'qq' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'qq'
|
|
|
|
UNION ALL SELECT 'wechat' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'wechat'
|
|
|
|
UNION ALL SELECT 'current_address' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'current_address'
|
|
|
|
UNION ALL SELECT 'home_address' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'home_address'
|
|
|
|
UNION ALL SELECT 'domicile_place' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'domicile_place'
|
|
|
|
UNION ALL SELECT 'postal_code' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'postal_code'
|
|
|
|
UNION ALL SELECT 'emergency_contact_name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_name'
|
|
|
|
UNION ALL SELECT 'emergency_contact_relation' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_relation'
|
|
|
|
UNION ALL SELECT 'emergency_contact_phone' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'emergency_contact_phone'
|
|
|
|
UNION ALL SELECT 'father_name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_name'
|
|
|
|
UNION ALL SELECT 'father_phone' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_phone'
|
|
|
|
UNION ALL SELECT 'father_work_unit' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'father_work_unit'
|
|
|
|
UNION ALL SELECT 'mother_name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_name'
|
|
|
|
UNION ALL SELECT 'mother_phone' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_phone'
|
|
|
|
UNION ALL SELECT 'mother_work_unit' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'mother_work_unit'
|
|
|
|
UNION ALL SELECT 'height' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'height'
|
|
|
|
UNION ALL SELECT 'weight' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'weight'
|
|
|
|
UNION ALL SELECT 'blood_type' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'blood_type'
|
|
|
|
UNION ALL SELECT 'special_condition' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'special_condition'
|
|
|
|
UNION ALL SELECT 'religion' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'religion'
|
|
|
|
UNION ALL SELECT 'hobbies' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'hobbies'
|
|
|
|
UNION ALL SELECT 'is_poor_student' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'is_poor_student'
|
|
|
|
UNION ALL SELECT 'poverty_level' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'poverty_level'
|
|
|
|
UNION ALL SELECT 'has_grant' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'has_grant'
|
|
|
|
UNION ALL SELECT 'grant_amount' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'grant_amount'
|
|
|
|
UNION ALL SELECT 'has_loan' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'has_loan'
|
|
|
|
UNION ALL SELECT 'loan_amount' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'loan_amount'
|
|
|
|
UNION ALL SELECT 'bank_card_no' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'bank_card_no'
|
|
|
|
UNION ALL SELECT 'bank_name' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'bank_name'
|
|
|
|
UNION ALL SELECT 'bank_branch' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'bank_branch'
|
|
|
|
UNION ALL SELECT 'info_status' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'info_status'
|
|
|
|
UNION ALL SELECT 'data_source' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'data_source'
|
|
|
|
UNION ALL SELECT 'last_batch_id' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'last_batch_id'
|
|
|
|
UNION ALL SELECT 'last_audit_time' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'last_audit_time'
|
|
|
|
UNION ALL SELECT 'ext_field1' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field1'
|
|
|
|
UNION ALL SELECT 'ext_field2' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field2'
|
|
|
|
UNION ALL SELECT 'ext_field3' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field3'
|
|
|
|
UNION ALL SELECT 'ext_field4' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field4'
|
|
|
|
UNION ALL SELECT 'ext_field5' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'ext_field5'
|
|
|
|
UNION ALL SELECT 'remark' as field_name, CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'remark';
|
|
|
|
-- 统计缺失字段
|
|
SELECT '=== 字段缺失统计 ===' as 'Result';
|
|
|
|
SELECT
|
|
(SELECT COUNT(*) FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info') as '数据库字段总数',
|
|
57 as '实体类字段总数',
|
|
(57 - (SELECT COUNT(DISTINCT column_name) FROM information_schema.COLUMNS WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name IN (
|
|
'id','student_no','id_card','name','name_pinyin','gender','birth_date','nation','political_status','student_status',
|
|
'enrollment_year','enrollment_date','school_system','education_level','training_type','major_code','major_name',
|
|
'class_code','class_name','college_code','college_name','phone','email','qq','wechat','current_address',
|
|
'home_address','domicile_place','postal_code','emergency_contact_name','emergency_contact_relation',
|
|
'emergency_contact_phone','father_name','father_phone','father_work_unit','mother_name','mother_phone',
|
|
'mother_work_unit','height','weight','blood_type','special_condition','religion','hobbies','is_poor_student',
|
|
'poverty_level','has_grant','grant_amount','has_loan','loan_amount','bank_card_no','bank_name','bank_branch',
|
|
'info_status','data_source','last_batch_id','last_audit_time','ext_field1','ext_field2','ext_field3','ext_field4','ext_field5','remark'
|
|
))) as '缺失字段数量';
|
|
|
|
-- 恢复外键检查
|
|
SET FOREIGN_KEY_CHECKS = 1;
|
|
|
|
-- ----------------------------
|
|
-- 脚本执行完成提示
|
|
-- ----------------------------
|
|
SELECT '==============================' as 'Result';
|
|
SELECT '✅ 字段完整性检查完成!' as 'Result';
|
|
SELECT '✅ 已添加religion字段' as 'Result';
|
|
SELECT '✅ 如有缺失字段请根据检查结果补充' as 'Result';
|
|
SELECT '==============================' as 'Result'; |