Home >Backend Development >PHP Tutorial > 导入表的有关问题

导入表的有关问题

WBOY
WBOYOriginal
2016-06-13 13:11:25965browse

导入表的问题
sql = insert into dx_gd_goods select * from dx_gd_goods2
上面的语名是把dx_gd_goods2 的数据 导入到 dx_gd_goods 里,当然也包括dx_gd_goods2 里的主键ID
我不想把主键ID导入进去,因为这样可能会造成主键重复而导入失败。我想要的是导入成功,而且主键永远都不可能重复,

我曾经这样试过

insert into dx_gd_goods select (a,b,c,d) from dx_gd_goods2
只读出dx_gd_goods2对应的字段,然后导入到dx_gd_goods里,但是失败了。

------解决方案--------------------
insert into dx_gd_goods(a,b,c....) select (a,b,c,d) from dx_gd_goods2 //指定字段导入
------解决方案--------------------

SQL code
insert into b(B1,B2...) (select A1,A2... from A)
<br><font color="#e78608">------解决方案--------------------</font><br>失败了 ? 那你将错误信息贴出来看看。
<br><font color="#e78608">------解决方案--------------------</font><br>把你的错误信息贴出来,这样也好分析问题
<br><font color="#e78608">------解决方案--------------------</font><br>你应该把具体的表结果贴出来<br><br>其实0涉及到id的字段用null来表示就可以了,比如a字段就是id,那么应该是<br>insert into dx_gd_goods select 'null',b,c,d from dx_gd_goods2
<br><font color="#e78608">------解决方案--------------------</font><br>你应该把具体的表结果贴出来<br><br>其实0涉及到id的字段用null来表示就可以了,比如a字段就是id,那么应该是<br>insert into dx_gd_goods select 'null',b,c,d from dx_gd_goods2
<br><font color="#e78608">------解决方案--------------------</font><br>你应该把具体的表结果贴出来<br><br>其实0涉及到id的字段用null来表示就可以了,比如a字段就是id,那么应该是<br>insert into dx_gd_goods select 'null',b,c,d from dx_gd_goods2 <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn