rollback_business_cards_table.sql 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- ===============================================
  2. -- 回滚business_cards表的age和native_place字段修改
  3. -- 执行日期: 请在执行前填写实际日期
  4. -- 回滚说明: 删除之前新增的age和native_place字段
  5. -- ===============================================
  6. -- 警告:执行此脚本将永久删除age和native_place字段及其数据
  7. -- 请确保已备份相关数据!
  8. -- 1. 检查字段是否存在
  9. SELECT
  10. column_name,
  11. data_type,
  12. is_nullable
  13. FROM information_schema.columns
  14. WHERE table_name = 'business_cards'
  15. AND column_name IN ('age', 'native_place')
  16. ORDER BY column_name;
  17. -- 2. 如果需要保留数据,可先导出这些字段的数据
  18. -- SELECT id, name_zh, age, native_place
  19. -- FROM business_cards
  20. -- WHERE age IS NOT NULL OR native_place IS NOT NULL;
  21. -- 3. 删除native_place字段
  22. ALTER TABLE business_cards
  23. DROP COLUMN IF EXISTS native_place;
  24. -- 4. 删除age字段
  25. ALTER TABLE business_cards
  26. DROP COLUMN IF EXISTS age;
  27. -- 5. 验证字段是否已删除
  28. SELECT
  29. column_name,
  30. data_type,
  31. is_nullable
  32. FROM information_schema.columns
  33. WHERE table_name = 'business_cards'
  34. AND column_name IN ('age', 'native_place')
  35. ORDER BY column_name;
  36. -- 6. 检查表结构
  37. \d business_cards;
  38. -- ===============================================
  39. -- 执行说明:
  40. -- 1. 此操作不可逆,请谨慎执行
  41. -- 2. 执行前请确保已备份相关数据
  42. -- 3. 建议在业务低峰期执行
  43. -- 4. 如果有应用程序依赖这些字段,请先更新应用代码
  44. -- ===============================================