今天寫的乙個是我在寫專案時要查詢各個時間段該單據不同的資料。我就想到了做乙個觸發器,當他插入或更新時往另一張表插入資料,拼接查詢。
好了,上**。
這是插入的觸發器
begin
insert
into assets_card_perform (
id,main_id,
depart_id,
depart_code,
depart_name,
assets_type_id,
assets_type_code,
assets_type_name,
assets_ori_value,
acc_deprec,
book_value,
manage_operator,
manage_operator_name,
mon_depre_amount,
spec_type,
storage_place,
use_depart_id,
use_depart_name,
use_operator,
use_operator_name,
use_status,
operator_date
)values
(null
, new.id,
new.depart_id,
new.depart_code,
new.depart_name,
new.assets_type_id,
new.assets_type_code,
new.assets_type_name,
new.assets_ori_value,
new.acc_deprec,
new.book_value,
new.manage_operator,
new.manage_operator_name,
new.mon_depre_amount,
new.spec_type,
new.storage_place,
new.use_depart_id,
new.use_depart_name,
new.use_operator,
new.use_operator_name,
new.use_status,
now())
;end
這是更新的觸發器
create
trigger card_perform_update after
update
on assets_card for each row
begin
insert
into assets_card_perform (
main_id,
depart_id,
depart_code,
depart_name,
assets_type_id,
assets_type_code,
assets_type_name,
assets_ori_value,
acc_deprec,
book_value,
manage_operator,
manage_operator_name,
mon_depre_amount,
spec_type,
storage_place,
use_depart_id,
use_depart_name,
use_operator,
use_operator_name,
use_status,
operator_date
)values
( new.id,
new.depart_id,
new.depart_code,
new.depart_name,
new.assets_type_id,
new.assets_type_code,
new.assets_type_name,
new.assets_ori_value,
new.acc_deprec,
new.book_value,
new.manage_operator,
new.manage_operator_name,
new.mon_depre_amount,
new.spec_type,
new.storage_place,
new.use_depart_id,
new.use_depart_name,
new.use_operator,
new.use_operator_name,
new.use_status,
now())
;end
後面還有乙個**查詢的拼接,還在研究中,研究完成更新! 建立觸發器
視覺化資料庫工具 對於 microsoft sql server 資料庫,可以在 transact sql 中編寫觸發器,而對於 oracle 資料庫,則可以在 pl sql 中進行編寫。通過指定下列內容建立觸發器 建立觸發器 在 伺服器資源管理器 中,展開 表 資料夾。右擊要在其上建立觸發器的表名...
建立觸發器
create trigger trigger insert test1 on test2 after insert asbegin set nocount on added to prevent extra result sets from interfering with select state...
建立觸發器
create or replace trigger tg student after insert or update or delete on student foreach row declare 定義變數 begin 記錄日誌的程式 操作型別 case when inserting then ...