Mysql給時間更新字段新增觸發器,

2021-08-20 13:24:25 字數 763 閱讀 4513

mysql表裡面都有建立時間欄位和更新時間字段

但是mysql資料庫只允許乙個欄位用timestamp

所以給更新字段新增如下觸發器。親測有效

delimiter $

create

trigger update_rt_onedescription_trigger before

update

on rt_onedescription for

each

rowbegin

set new.update_time = now();

end$ delimiter ;

用於對觸發器語句各個欄位的理解。

create

trigger trigger_name

trigger_time

trigger_event on tbl_name

foreach

rowtrigger_stmt

其中:

trigger_name:標識觸發器名稱,使用者自行指定;

trigger_time:標識觸發時機,取值為 before 或 after;

trigger_event:標識觸發事件,取值為 insert、update 或 delete;

tbl_name:標識建立觸發器的表名,即在哪張表上建立觸發器;

trigger_stmt:觸發器程式體,可以是一句sql語句,或者用 begin 和 end 包含的多條語句。

Zen Cart給產品新增新字段

zen cart 二次開發 shoppingmars.com zen cart 二次開發 2 在資料庫管理介面 如 phpmyadmin 中找到表 products 或者表的字首加 products 為這個表新增兩個字段 products guarantee 和 products color alt...

mysql更新 Mysql更新欄位中部分資料的方法

如果現在需要mysql更新欄位重部分資料,而不是全部資料,應該採用何種方法呢?下面介紹了兩種情況下mysql更新欄位中部分資料的方法,供您參考。mysql更新欄位中部分資料 種情況 update tab set a concat substring a,1,3 bbb 從a的1個字元開始取3個字元,...

mongodb 實現新增新字段(使用更新操作)

由於不能再mongo中直接對錶中的字段進行新增,所以我們需要通過更新來實現新增新字段的操作 if course name in mongodb courses collection db course name for c in collection.find collection.update 我...