MySQL trigger before Insert value Checking

后端 未结 3 1691
刺人心
刺人心 2021-01-01 22:51

I have a table staff with office column. Currently the office column do not accept NULL values. The application persisting onto this t

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-01 23:12

    Shouldn't it be something like this:

    DELIMITER $$
    
    CREATE TRIGGER staffOfficeNullReplacerTrigger BEFORE INSERT ON Staff
    FOR EACH ROW BEGIN
       IF (NEW.office IS NULL) THEN
            INSERT INTO Staff(office) VALUES("N/A");
       END IF;
    END$$
    

提交回复
热议问题