如何在sql中触发此过程?

时间:2018-06-06 22:18:53

标签: sql mariadb

我的想法是进行交易,例如当我输入姓氏年龄和客户金额时,流程将使用费率表的费率触发交易,姓名和年龄将相同作为表客户!

Create TRIGGER  MYtrigger
    AFTER INSERT trigger.customer 
    BEGIN 
    INSERT INTO trigger.transaction (
    Name, Surname, Age,Exchange)
    VALUES  (customer.Name,customer.Surname,customer.Age,customer.Amount*rate.Rate);
    END

2 个答案:

答案 0 :(得分:1)

试试这个:

delimiter $$

Create TRIGGER  MYtrigger AFTER INSERT trigger.customer 
BEGIN 
    INSERT INTO trigger.transaction (Name, Surname, Age, Exchange)
        VALUES  (new.Name, new.Surname, new.Age, new.Amount*rate.Rate);
END;$$

delimiter ;

那就是说,你现在遇到rate的问题。我不知道那是什么,但它暗示了这样的事情:

delimiter $$

Create TRIGGER  MYtrigger AFTER INSERT trigger.customer 
BEGIN 
    INSERT INTO trigger.transaction (Name, Surname, Age, Exchange)
        SELECT new.Name, new.Surname, new.Age, new.Amount*r.Rate
        FROM rate r
        WHERE r.? = new.?;  -- not the faintest idea what is used for the match
END;$$

delimiter ;

答案 1 :(得分:0)

  

应在问题的变化中更改表的名称

>DELIMITER $$ CREATE TRIGGER `myTrigger`  
> AFTER INSERT ON `customer` 
> FOR EACH ROW  
> BEGIN 
> INSERT INTO bonus.tra (cus_id ,
>                         name,
>                         surname,
>                         age,
>                         exchange)
>                         
>                         VALUES (
>                         new.cus_id,
>                         new.name,
>                         new.surname,
>                         new.age,
>                         new.amount *(SELECT rate_ra from rate));
>                             END $$ 
DELIMITER ;