简体   繁体   English

使用联接表创建SQL转储

[英]Create a SQL dump with join tables

I have to transfer the following select into a single table: 我必须将以下选择转移到一个表中:

SELECT  
o.objektnummer, su.subunternehmernummer,
a.artikelnummer, a.artikel, a.beschreibung,
a.einheit, a.preis_pro_einheit, a.anzahl_parameter, a.p1_einheit, a.p2_einheit, a.p3_einheit,
a.mbs_artikel, a.su_gewerk, a.preis_status,
a.mindermenge_kleiner_als, a.zulage_mindermengen_artikel_nummer
FROM
objekt_artikel oa
INNER JOIN objekt o ON o.id = oa.id_objekt
INNER JOIN artikel a ON a.id = oa.id_artikel
INNER JOIN subunternehmer_objekt suo ON suo.id_objekt = o.id
INNER JOIN subunternehmer su ON su.id = suo.id_subunternehmer

This is the insert i nead: 这是我需要的插入内容:

INSERT INTO objekt_artikel (
                    id_objekt, id_subunternehmer,
                    artikelnummer, artikel, beschreibung,
                    einheit, preis_pro_einheit, anzahl_parameter, p1_einheit, p2_einheit, p3_einheit,
                    mbs_artikel, su_gewerk, preis_status,
                    mindermenge_kleiner_als, zulage_mindermengen_artikel_nummer
                     )

If i set Limit to 1000, then the select works perfect and the insert could be done, but the table from the select have over 19 000 000 rows and this makes the server crashing. 如果我将Limit设置为1000,则select可以完美工作,并且可以完成插入,但是select的表有超过19000000行,这会使服务器崩溃。 My idea is now, that i make a sql-dump with this select, but i think the problem is that i have so much inner joins in it. 我的想法是,现在我使用此选择进行sql-dump,但我认为问题在于我有太多内部联接。

Can i make a output with this select to a file? 我可以将这个选择输出到文件吗? seperatet by semikolon? 用分号分隔?

I have not worked with 19 million rows! 我没有处理1900万行! But I can think of one solution that can be implemented by whoever is calling these SQL statements. 但是我可以想到一种可以由调用这些SQL语句的人实施的解决方案。 I give the pseudo-code below: 我在下面给出伪代码:

for ($start=0, $limit=1000; ; $start += $limit) {
    $result = execute("SELECT * FROM $tableName LIMIT $start, $limit");
    if ($result) insertToTable($result);
    else break;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM