无法更新存储函数/触发器中的表“ companystructures”,因为调用该存储函数/触发器的语句已使用该表

时间:2019-03-04 16:30:50

标签: php mysql

我创建了一个插入前触发器,该触发器生成一个唯一代码以更新表的公司结构(在mysql中)。当我尝试提交表格时,我一直保持联系。

  

无法更新存储函数/触发器中的表'companystructures',因为调用该存储函数/触发器的语句已使用该表

我对此很陌生。

BEGIN
    DECLARE cd_count int;
    SET cd_count=0;
     IF NEW.type = 'Department' THEN
      INSERT INTO companystructures SET companystructures.comp_code = concat('D',(SELECT count(*) from companystructures WHERE type = 'Department')+1);

 ELSEIF NEW.type = 'Unit' THEN
  INSERT INTO companystructures SET companystructures.comp_code = concat('U', (SELECT count(*) from companystructures WHERE type = 'Unit')+1);

  ELSEIF NEW.type = 'Regional Office' THEN
  INSERT INTO companystructures SET companystructures.comp_code = concat('R', (SELECT count(*) from companystructures WHERE type = 'Regional Office')+1);

  ELSEIF NEW.type = 'Head Office' THEN
  INSERT INTO companystructures SET companystructures.comp_code = concat('H', (SELECT count(*) from companystructures WHERE type = 'Head Office')+1);

  ELSEIF NEW.type = 'Company' THEN 
  INSERT INTO companystructures SET companystructures.comp_code = concat('C', (SELECT count(*) from companystructures WHERE type = 'Company')+1);
 END IF;
 END

0 个答案:

没有答案