mysql 觸發器 分行 mysql 觸發器

2021-10-22 05:15:49 字數 2348 閱讀 6739

mysql 觸發器中有兩個insert 語句 第二個inert 要用第乙個insert 的結果怎麼實現

delimiter $$

use `nightclub`$$

drop trigger /*!50032 if exists */ `create_histroy_room_statuses`$$

create

/*!50017 definer = 'root'@'localhost' */

trigger `create_histroy_room_statuses` before delete on `room_statuses`

for each row

begin

insert `nightclub`.histroy_room_statuses (

room_id,

note,

customer_number,

arrival_time,

room_game,

drinks,

booking_time,

estimated_time,

assistant_table,

visitor,

cadres_patrol,

salesman_tip,

master_tip,

princess_tip,

drink_total,

prs_tip_total,

towel_number,

consume,

pay_method,

princess_customer_tel,

princess_customer_name,

createdat,

updatedat,

booking_employee_id,

princess_id,

salesman_id,

master_id,

booking_customer_tel,

booking_customer_name,

state,

enter_time

) select

room_id,

note,

customer_number,

arrival_time,

room_game,

drinks,

booking_time,

estimated_time,

assistant_table,

visitor,

cadres_patrol,

salesman_tip,

master_tip,

princess_tip,

drink_total,

prs_tip_total,

towel_number,

consume,

pay_method,

princess_customer_tel,

princess_customer_name,

createdat,

updatedat,

booking_employee_id,

princess_id,

salesman_id,

master_id,

booking_customer_tel,

booking_customer_name,

state,

enter_time

from `nightclub`.room_statuses

where room_id = old.room_id;

insert into histroy_room_status_prs (

employee_id,

room_id,

createdat,

updatedat,

customer_name,

customer_tel,

i***emptfee,

charge,

work_time

) select

employee_id,

room_id,

createdat,

updatedat,

customer_name,

customer_tel,

i***emptfee,

charge,

work_time

from

room_status_prs where room_id=old.room_id;

end;

delimiter ;

histroy_room_status_prs 表我建立外來鍵 但是獲取不到第乙個insert 返回的值 該怎麼實現 那位高手指點一下謝謝

my sql 觸發器 mysql建立觸發器

首先,我們來了解一下什麼是觸發器,觸發器,就是在對一張表資料進行增 insert 刪 delete 改 update 的時候,為了保持資料的一致性,對別的表也要進行相應的資料修改。我們都知道mysql最後事務提交後,資料是會儲存到磁碟上的,那麼每次在insert,delete,update時候舊資料...

my sql 觸發器 MySQL檢視觸發器

檢視觸發器是指檢視資料庫中已經存在的觸發器的定義 狀態和語法資訊等。mysql 中檢視觸發器的方法包括 show triggers 語句和查詢 information schema 資料庫下的 triggers 資料表等。本節將詳細介紹這兩種檢視觸發器的方法。show triggers語句檢視觸發器...

mysql 觸發器定義 mysql觸發器

什麼是觸發器 觸發器是與表有關的資料庫物件,在滿足定義條件時觸發,並執行觸發器中定義的語句集合。觸發器的這種特性可以協助應用在資料庫端確保資料的完整性。舉個例子,比如你現在有兩個表 使用者表 和 日誌表 當乙個使用者被建立的時候,就需要在日誌表中插入建立的log日誌,如果在不使用觸發器的情況下,你需...