12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- -- ===============================================
- -- 回滚business_cards表的age和native_place字段修改
- -- 执行日期: 请在执行前填写实际日期
- -- 回滚说明: 删除之前新增的age和native_place字段
- -- ===============================================
- -- 警告:执行此脚本将永久删除age和native_place字段及其数据
- -- 请确保已备份相关数据!
- -- 1. 检查字段是否存在
- SELECT
- column_name,
- data_type,
- is_nullable
- FROM information_schema.columns
- WHERE table_name = 'business_cards'
- AND column_name IN ('age', 'native_place')
- ORDER BY column_name;
- -- 2. 如果需要保留数据,可先导出这些字段的数据
- -- SELECT id, name_zh, age, native_place
- -- FROM business_cards
- -- WHERE age IS NOT NULL OR native_place IS NOT NULL;
- -- 3. 删除native_place字段
- ALTER TABLE business_cards
- DROP COLUMN IF EXISTS native_place;
- -- 4. 删除age字段
- ALTER TABLE business_cards
- DROP COLUMN IF EXISTS age;
- -- 5. 验证字段是否已删除
- SELECT
- column_name,
- data_type,
- is_nullable
- FROM information_schema.columns
- WHERE table_name = 'business_cards'
- AND column_name IN ('age', 'native_place')
- ORDER BY column_name;
- -- 6. 检查表结构
- \d business_cards;
- -- ===============================================
- -- 执行说明:
- -- 1. 此操作不可逆,请谨慎执行
- -- 2. 执行前请确保已备份相关数据
- -- 3. 建议在业务低峰期执行
- -- 4. 如果有应用程序依赖这些字段,请先更新应用代码
- -- ===============================================
|