-- ==========================================
-- 删除 delivery 表的所有触发器
-- ==========================================

USE cattletrade;

-- 查看所有 delivery 相关触发器
SELECT '当前 delivery 表的触发器:' as '状态';
SHOW TRIGGERS WHERE `Table` = 'delivery';

-- 删除所有可能的触发器变体
DROP TRIGGER IF EXISTS trg_delivery_fill_from_driver;
DROP TRIGGER IF EXISTS `trg_delivery_fill_from_driver`;

-- 如果有 UPDATE 版本的触发器
DROP TRIGGER IF EXISTS trg_delivery_fill_from_driver_update;
DROP TRIGGER IF EXISTS trg_delivery_update_from_driver;

-- 查询数据库中所有包含 delivery 的触发器名称
SELECT TRIGGER_NAME 
FROM INFORMATION_SCHEMA.TRIGGERS 
WHERE TRIGGER_SCHEMA = 'cattletrade' 
  AND EVENT_OBJECT_TABLE = 'delivery';

-- 验证是否还有触发器
SELECT '删除后的触发器列表:' as '状态';
SHOW TRIGGERS WHERE `Table` = 'delivery';

-- 最终验证：确认没有触发器引用 car_number
SELECT '检查是否还有触发器引用 car_number:' as '状态';
SELECT 
    TRIGGER_NAME,
    EVENT_MANIPULATION,
    EVENT_OBJECT_TABLE
FROM INFORMATION_SCHEMA.TRIGGERS
WHERE TRIGGER_SCHEMA = 'cattletrade'
  AND ACTION_STATEMENT LIKE '%car_number%';

