Files
hr-position-system/clear_database.sql
DonaldFang 方士碩 a6af297623 backup: 完成 HR_position_ 表格前綴重命名與欄位對照表整理
變更內容:
- 所有資料表加上 HR_position_ 前綴
- 整理完整欄位顯示名稱與 ID 對照表
- 模組化 JS 檔案 (admin.js, ai.js, csv.js 等)
- 專案結構優化 (docs/, scripts/, tests/ 等)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 12:05:20 +08:00

84 lines
2.9 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.

-- HR Position System - 清空資料庫腳本
-- 只清空業務資料,保留表結構和參照代碼
-- 執行前請確認備份重要資料
USE hr_position_system;
-- ============================================================
-- 1. 停用外鍵檢查(避免刪除順序問題)
-- ============================================================
SET FOREIGN_KEY_CHECKS = 0;
-- ============================================================
-- 2. 清空業務資料表(保留表結構)
-- ============================================================
-- 清空組織崗位關聯表
TRUNCATE TABLE HR_position_organization_positions;
-- 清空部級單位表
TRUNCATE TABLE HR_position_departments;
-- 清空處級單位表
TRUNCATE TABLE HR_position_divisions;
-- 清空事業體表
TRUNCATE TABLE HR_position_business_units;
-- 清空崗位描述表
TRUNCATE TABLE HR_position_job_descriptions;
-- 清空職務基礎資料表
TRUNCATE TABLE HR_position_jobs;
-- 清空崗位基礎資料表
TRUNCATE TABLE HR_position_positions;
-- 清空審計日誌表
TRUNCATE TABLE HR_position_audit_logs;
-- ============================================================
-- 3. 重新啟用外鍵檢查
-- ============================================================
SET FOREIGN_KEY_CHECKS = 1;
-- ============================================================
-- 4. 確認參照代碼表資料保留(不清空)
-- ============================================================
-- reference_codes 表保留所有參照代碼資料
-- 包含POSITION_CATEGORY, POSITION_NATURE, POSITION_LEVEL,
-- JOB_CATEGORY, EDUCATION, SALARY_RANGE, WORK_LOCATION,
-- EMP_ATTRIBUTE, RECRUIT_POSITION, TITLE_REQ
-- 確認參照代碼數量
SELECT code_type, COUNT(*) as count
FROM HR_position_reference_codes
GROUP BY code_type
ORDER BY code_type;
-- ============================================================
-- 5. 顯示清空結果
-- ============================================================
SELECT 'HR_position_organization_positions' as table_name, COUNT(*) as row_count FROM HR_position_organization_positions
UNION ALL
SELECT 'HR_position_departments', COUNT(*) FROM HR_position_departments
UNION ALL
SELECT 'HR_position_divisions', COUNT(*) FROM HR_position_divisions
UNION ALL
SELECT 'HR_position_business_units', COUNT(*) FROM HR_position_business_units
UNION ALL
SELECT 'HR_position_job_descriptions', COUNT(*) FROM HR_position_job_descriptions
UNION ALL
SELECT 'HR_position_jobs', COUNT(*) FROM HR_position_jobs
UNION ALL
SELECT 'HR_position_positions', COUNT(*) FROM HR_position_positions
UNION ALL
SELECT 'HR_position_audit_logs', COUNT(*) FROM HR_position_audit_logs
UNION ALL
SELECT 'HR_position_reference_codes (保留)', COUNT(*) FROM HR_position_reference_codes;
-- ============================================================
-- 完成訊息
-- ============================================================
SELECT '資料庫清空完成!參照代碼已保留。' as message;