在phpmyadmin中INSERT之后触发

时间:2017-06-12 19:38:21

标签: mysql sql phpmyadmin

我有一个处理CSV上传到数据库的网站。上传工作但我过去遇到过问题,触发器来自phpmyadmin。

CSV文件可以有5到20行/条记录,但无论它们有230列。上传首先将所有这些放入相同大小的临时表中。 上传并插入数据库后,我有几个QA检查,我现在手动应用。如果我将它们粘贴到phpmyadmin中,它们会按照应有的方式进行工作,但我需要创建一个触发器,在上传完成后立即执行这些检查。

我对SQL很新,但想法是:上传后,如果CSV中有20行,则所有20行都会被迭代并插入到暂存中,一旦插入完成,我想要整个触发器发生在我的演出'表。

这是我的触发器代码,但PHPmyadmin给了我一个语法错误:

CREATE TRIGGER QAtrigger
AFTER INSERT ON `staging`
FOR EACH ROW
BEGIN

UPDATE staging 
SET  `miuFlag` =1 
WHERE  `lowSideMIUNumArriv` =    `lowSideMIUNumDepart` 
AND  `miu` =  "NO";

UPDATE staging 
SET  `miuFlag` =1 
WHERE  `lowSideMIUNumArriv` !=    `lowSideMIUNumDepart` 
AND  `miu` =  "YES";

UPDATE staging 
SET  `miuFlag` =0
WHERE  `lowSideMIUNumArriv` =    `lowSideMIUNumDepart` 
AND  `miu` =  "YES";

UPDATE staging 
SET  `miuFlag` =0 
WHERE  `lowSideMIUNumArriv` !=    `lowSideMIUNumDepart` 
AND  `miu` =  "No";

 UPDATE staging 
SET  `testPortFlag` =1 
WHERE  `testPort` =   "Present" 
AND  `testPortInstalled` =  "NO";

UPDATE staging 
SET  `testPortFlag` =1 
WHERE  `testPort` =   "Installed" 
AND  `testPortInstalled` =  "YES";


UPDATE staging 
SET  `workOrderFlag` =0 
WHERE `workOrderType2` = "ONSITE SURVEY TEST AND REPAIR"
AND  `completeMeter` = "NO"
AND  `ume` =  "NO"
AND  `discChamber` =  "NO"
AND  `turbineChamber` =  "NO"
AND `automaticValve`  =  "NO"
AND  `strainer` =  "NO"
AND  `lowRegister` =  "NO"
AND  `highRegister` =  "NO"
AND  `miu` =  "NO"
AND  `antennae` =  "NO"
AND  `calibrationVane` =  "NO"
AND  `meterLeakRepaired` =  "NO";

UPDATE staging 
SET  `workOrderFlag` =1
WHERE `workOrderType2` = "ONSITE SURVEY TEST AND REPAIR"
AND  `completeMeter` = "YES"
OR  `ume` =  "YES"
OR  `discChamber` =  "YES"
OR  `turbineChamber` =  "YES"
OR `automaticValve`  =  "YES"
OR  `strainer` =  "YES"
OR  `lowRegister` =  "YES"
OR  `highRegister` =  "YES"
OR  `miu` =  "YES"
OR  `antennae` =  "YES"
OR  `calibrationVane` =  "YES"
OR  `meterLeakRepaired` =  "YES";


UPDATE staging 
SET  `leakFlag` =1 
WHERE  `apparentLeak` =   "NO" 
AND  `leakLocation` =  "NONE"
AND `leakType` = "UNKNOWN"
OR  `apparentLeak` =   "NO" 
AND `leakLocation` =  "NONE"
AND `leakType` = "NONE"
OR  `apparentLeak` =   "NO" 
AND `leakLocation` =  "NONE"
AND `leakType` = "N/A";
END

0 个答案:

没有答案