一张表中两个字段需同时要默认获取当时时间(红色字那字段),如何创建触发器  create table pmt_detail_dm(
DMId Varchar(4) not null, /*DM促销期数*/
SupId integer not null, /*供应商代码*/
ProId integer not null, /*商品代码*/
OrigInPrice dec(10,2) not null, /*原进价*/
InPrice dec(10,2) not null, /*促销进价*/
OrigSalePrice dec(10,2) not null, /*原售价*/
SalePrice dec(10,2) not null, /*促销售价*/
OrigMemPrice dec(10,2) null, /*原会员价*/
SpecialPrice dec(10,2) null, /*印花价*/
PrePurQty integer null, /*预订进数*/
PreSaleQty integer null, /*预定销量*/
GiftOne Integer null, /*搭赠比1*/
GiftTwo Integer null, /*搭赠比2*/
LimitTimes Integer null, /*限购次数*/
LimitQty integer null, /*限购数量*/
OperatorId char(10) null, /*操作员*/
CreateDate timestamp default current_timestamp(),
UpdateDate timestamp ,
Re varchar(40) null,
SpecBegindate timestamp null, 
SpecEndDate timestamp null, constraint p_pmt_detail_dm primary key(DMId,SupId,ProId)

解决方案 »

  1.   

    在TRIGGER中
    set new.UpdateDate=current_timestamp
      

  2.   

    不用触发器  更新时间换成datatime 用程序来更新
      

  3.   

    create trigger trg_pmt_detail_dm_before_insert before insert 
    on pmt_detail_dm
    for each row
    insert into pmt_detail_dm set new.UpdateDate = current_timestamp;
    是不是这样写
      

  4.   

    写了上面那句后,能运行成功。但我不能对这张表进行UPdate insert等操作有MYsql     QQ群吗
      

  5.   

    在MYSQL的TRIGGER中不能对本表操作
      

  6.   


    create trigger trg_pmt_detail_dm_before_insert before insert  
    on pmt_detail_dm
    for each row
     set new.UpdateDate = current_timestamp;
    是不是这样写
      

  7.   

    当然有。你可以自己在QQ中搜索MYSQL群。
      

  8.   

    非常谢谢你,为什么直接用set new.UpdateDate = current_timestamp;就可以了,你也没有判断啊
      

  9.   

    建议参考一下手册中的语法。
    IF new.xxxx is null then 
      

  10.   

    为NUll 时取当前时间,不为空我也要取当前时间,上面那语句 可以成功吗?