dsrnwngq411594 2017-05-23 12:15
浏览 58
已采纳

修改请求SQL

I have a table SQL and I fill it from an Excel File. The problem is many fields are repeated. For example:

FOURNITURE      MFC       SERIE  
FOURNITURE      MFC       SERIE 
FOURNITURE      MFC       SERIE 

Here in my table, I find just one line. It jumps up all the rest. However, I need to get all the lines.

My request is:

if ($articleid == 'DIEPRESTATION' || $articleid == 'DIEDIVBIEN' ||$articleid =='DIEDIVERS')
{
    if(!($this->_db->query("INSERT INTO `article` (`ID_Article`, `Designiation`, `Ident`, `ID_LRU`) VALUES ('".$articleid."', '".$designation."', '".$ident."', '".$IdLRU."');")))
{   
        if ($LRU != 'new')
        {
          return $this->_db->query(" UPDATE  `FLOOSE`.`article` SET  `ID_LRU` =  
          '".$IdLRU."' WHERE  `article`.`ID_Article` =  '".$articleid."' AND  
            `article`.`Designiation` =  '".$designation."' AND  
             `article`.`Ident` =  '".$ident."' LIMIT 1 ;");
        } 
        else {
                return false;
            }
        } else{
            return TRUE;
        }
    }

I think I have a unique key constraint on two table columns. screen sheet of the structure of my table

How can I change it or take a test to recover all the lines? I delete the unique key constraint ? Thank you.

  • 写回答

1条回答 默认 最新

  • dongping2023 2017-05-23 12:52
    关注

    Yes you do have a unique constraint on your columns. And even more, the composite of ID_Article, Designiation is your primary key, which is per definition also unique.

    You should

    1. remove that primary key: ALTER TABLE article DROP PRIMARY KEY;
    2. add another field (name it id to stick with conventions), and set it as primary key with auto-increment: ALTER TABLE article ADD id INT PRIMARY KEY AUTO_INCREMENT;
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line