3 Stimmen

Was ist ein guter Weg, um SQL einer Ansicht aus MySQL zu formatieren

Wie die meisten von Ihnen wissen würden, wenn Sie eine Ansicht in MYSQL speichern und sie später abrufen, ist sie alles in nativem MYSQL, sieht schrecklich aus - keine Zeilenumbrüche, Einrückungen, eine Menge UTF-Codierungstags, die herumliegen und Ihren Code wie sql-Suppe aussehen lassen.

Hat jemand ein Programm oder empfiehlt ein Plugin für Netbeans, das ich verwenden kann, um dieses SQL zu formatieren? Hier ist meine Ansicht, versuchen Sie, sie zu formatieren und geben Sie sie als Beispiel erneut ein, wenn Sie möchten :)

    /* ALGORITHM=UNDEFINED */ SELECT `e`.`Australia` AS `audit_anps`,`e`.`audit_end_date` AS `audit_auditenddate`,`e`.`BumperIssueDates` AS `audit_bumperissuedates`,`e`.`BumperIssuesLinked` AS `audit_bumperissuelinked`,`e`.`BumperIssues` AS `audit_bumperissues`,`e`.`bundledSales` AS `audit_bundledsales`,`e`.`CoverPrice` AS `audit_coverprice`,`e`.`CoverPrice2` AS `audit_coverprice2`,`e`.`CoverPrice2Day` AS `audit_coverprice2day`,`e`.`CoverPrice3` AS `audit_coverprice3`,`e`.`CoverPrice3Day` AS `audit_coverprice3day`,`e`.`CoverPrice4` AS `audit_coverprice4`,`e`.`CoverPrice4Day` AS `audit_coverprice4day`,`e`.`CoverPriceDay` AS `audit_coverpriceday`,`e`.`timestamp` AS `audit_datecreated`,`e`.`weeksbetween` AS `audit_daysbetween`,_utf8'' AS `audit_dayspublished`,`e`.`AustraliaDigital` AS `audit_digital_anps`,`e`.`BumperIssueDatesD` AS `audit_digital_bumperissuedates`,`e`.`BumperIssuesD` AS `audit_digital_bumperissues`,`e`.`BumperIssuesLinkedD` AS `audit_digital_bumperissueslinked`,`e`.`bundledSalesDigital` AS `audit_digital_bundledsalesdigital`,`e`.`CoverPriceD` AS `audit_digital_coverprice`,`e`.`CoverPrice2D` AS `audit_digital_coverprice2`,`e`.`CoverPrice2DayD` AS `audit_digital_coverprice2day`,`e`.`CoverPrice3D` AS `audit_digital_coverprice3`,`e`.`CoverPrice3DayD` AS `audit_digital_coverprice3day`,`e`.`CoverPrice4D` AS `audit_digital_coverprice4`,`e`.`CoverPrice4DayD` AS `audit_digital_coverprice4day`,`e`.`CoverPriceDayD` AS `audit_digital_coverpriceday`,`e`.`ExcludedDatesD` AS `audit_digital_excludeddates`,`e`.`inclAccomAirlinesSalesDigital` AS `audit_digital_inclaccomairlinesales`,`e`.`inclEducationalSalesDigital` AS `audit_digital_incleducationalsales`,`e`.`inclEventSalesDigital` AS `audit_digital_incleventsales`,`e`.`inclMultiplePublicationSalesDigital` AS `audit_digital_inclmultiplepublicationsales`,`e`.`IssuesD` AS `audit_digital_issues`,`e`.`IssuesAuditedD` AS `audit_digital_issuesaudited`,`e`.`NonPublishingDatesD` AS `audit_digital_nonpublishingdates`,`e`.`RemarksD` AS `audit_digital_remarks`,`e`.`exclAustraliaOther` AS `audit_exclaustraliaother`,`e`.`exclInExcess` AS `audit_exclinexcess`,`e`.`ExcludedDates` AS `audit_excludeddates`,`e`.`Exclusions` AS `audit_exclusions`,`e`.`FrequencyID` AS `audit_frequencyid`,`e`.`inclAccomAirlineSales` AS `audit_inclaccomairlinesales`,`e`.`inclEducationalSales` AS `audit_incleducationalsales`,`e`.`inclEventSales` AS `audit_incleventsales`,`e`.`inclMultiplePublicationSales` AS `audit_inclmultiplepublicationsales`,`e`.`InExcess` AS `audit_inexcess`,`e`.`Issues` AS `audit_issues`,`e`.`IssuesAudited` AS `audit_issuesaudited`,`e`.`NimsAvCopiesDelivered` AS `audit_nimaveragecopiesdelivered`,`e`.`NimsAvCopiesMailed` AS `audit_nimaveragecopiesmailed`,`e`.`NimsAvCopiesPrinted` AS `audit_nimaveragecopiesprinted`,`e`.`NIMCopiesDelivered` AS `audit_nimcopiesdelivered`,`e`.`NIMCopiesMailed` AS `audit_nimcopiesmailed`,`e`.`NIMCopiesPrinted` AS `audit_nimcopiesprinted`,`e`.`NonPublishingDates` AS `audit_nonpublishingdates`,`e`.`NZInExcess` AS `audit_nzinexcess`,`e`.`NewZealand` AS `audit_nznps`,`e`.`OCInExcess` AS `audit_ocinexcess`,`e`.`OSMoney` AS `audit_osmoney`,`e`.`OtherCountries` AS `audit_othercountries`,_utf8'' AS `audit_parentpublication`,`e`.`AuditPeriod` AS `audit_period`,`e`.`periodAdjustment` AS `audit_periodadjustment`,`e`.`periodAdjustmentValue` AS `audit_periodadjustmentvalue`,_utf8'' AS `audit_periodenddate`,_utf8'' AS `audit_periodstartdate`,`e`.`PubID` AS `audit_pubid`,`e`.`comments` AS `audit_remarks`,`e`.`SpecialPublishingDay` AS `audit_specialpublishingday`,`e`.`stageid` AS `audit_stageid`,`e`.`totalIssuesAudited` AS `audit_totalissuesaudited`,`e`.`lAuditType` AS `audit_type`,`e`.`iYear` AS `audit_year`,`e`.`AuditorEmail` AS `deprecated_AuditorEmail`,`e`.`AuditorName` AS `deprecated_AuditorName`,`e`.`dateAuditorApproved` AS `deprecated_dateAuditorApproved`,`e`.`dateSignatoryApproved` AS `deprecated_dateSignatoryApproved`,`e`.`dateSubmitted` AS `deprecated_dateSubmitted`,`e`.`DayPublished` AS `deprecated_dayspublished`,`e`.`FirstSignatoryEmail` AS `deprecated_FirstSignatoryEmail`,`e`.`FirstSignatoryName` AS `deprecated_FirstSignatoryName`,`e`.`FormStatus` AS `deprecated_FormStatus`,`e`.`lodgementstatus` AS `deprecated_lodgementstatus`,`e`.`lodgementtype` AS `deprecated_lodgementtype`,`e`.`nPeriod` AS `deprecated_nPeriod`,`e`.`nYear` AS `deprecated_nYear`,`e`.`s2complete` AS `deprecated_s2complete`,`e`.`s3complete` AS `deprecated_s3complete`,`e`.`SecondSignatoryEmail` AS `deprecated_SecondSignatoryEmail`,`e`.`SecondSignatoryName` AS `deprecated_SecondSignatoryName`
FROM (`auau7859_aba`.`el_abc_stage` `e` LEFT JOIN `auau7859_aba`.`el_abc_status` `s` ON((`s`.`stageid` = `e`.`stageid`)))
WHERE ((`s`.`statusid` = (SELECT `h`.`statusid` AS `statusid`
FROM `auau7859_aba`.`el_abc_status` `h` WHERE (`h`.`stageid` = `s`.`stageid`) ORDER BY `h`.`statusid` DESC
LIMIT 1)) AND (`s`.`currentstatus` = _latin1'complete'))

Hässlich, oder? Immer wenn ich die Codeformatierung in Netbeans oder in Heidi SQL verwende, wird jede Sektion (FROM/WHERE/LIMIT/SELECT) in eine neue Zeile geschrieben. Das ist nicht gut, weil mein SELECT-Statement so lang ist. Ich brauche etwas, das zumindest jedes Select-Feld in eine neue Zeile schreibt.

Kannst du mir helfen?

Danke.

3voto

nick mason Punkte 1

Erstellen Sie eine gespeicherte Prozedur, um die Ansicht neu zu erstellen. Das ermöglicht es Ihnen, Ihr Format beizubehalten und Kommentare hinzuzufügen, um die Ansicht zu dokumentieren. Ich benenne meine als sp_create_viewname

0voto

Jason Punkte 14478

Ich benutze squirrel SQL.

Die Anwendung selbst ist etwas schwerer für mich zu bedienen als Heidi SQL (von dem ich schwärme), aber die SQL-Formatierungsfunktionalität von Heidi ist nicht so überragend wie die von Squirrel.

http://squirrel-sql.sourceforge.net/

Es kann den schrecklichen Code einer Ansicht perfekt und ohne Probleme formatieren.

0voto

Guido Punkte 826

Mit einem Klick erledigt in einem kostenlosen Online-SQLFormatter

/* ALGORITHM=UNDEFINED */

AUSWÄHLEN

     `e`.`Australia`                          AS `audit_anps`
    ,`e`.`audit_end_date`                      AS `audit_auditenddate`
    ,`e`.`BumperIssueDates`                    AS `audit_bumperissuedates`
    ,`e`.`BumperIssuesLinked`                  AS `audit_bumperissuelinked`
    ,`e`.`BumperIssues`                        AS `audit_bumperissues`
    ,`e`.`bundledSales`                        AS `audit_bundledsales`
    ,`e`.`CoverPrice`                          AS `audit_coverprice`
    ,`e`.`CoverPrice2`                         AS `audit_coverprice2`
    ,`e`.`CoverPrice2Day`                      AS `audit_coverprice2day`
    ,`e`.`CoverPrice3`                         AS `audit_coverprice3`
    ,`e`.`CoverPrice3Day`                      AS `audit_coverprice3day`
    ,`e`.`CoverPrice4`                         AS `audit_coverprice4`
    ,`e`.`CoverPrice4Day`                      AS `audit_coverprice4day`
    ,`e`.`CoverPriceDay`                       AS `audit_coverpriceday`
    ,`e`.`timestamp`                           AS `audit_datecreated`
    ,`e`.`weeksbetween`                        AS `audit_daysbetween`
    , _utf8''                                  AS `audit_dayspublished`
    ,`e`.`AustraliaDigital`                    AS `audit_digital_anps`
    ,`e`.`BumperIssueDatesD`                   AS `audit_digital_bumperissuedates`
    ,`e`.`BumperIssuesD`                       AS `audit_digital_bumperissues`
    ,`e`.`BumperIssuesLinkedD`                 AS `audit_digital_bumperissueslinked`
    ,`e`.`bundledSalesDigital`                 AS `audit_digital_bundledsalesdigital`
    ,`e`.`CoverPriceD`                         AS `audit_digital_coverprice`
    ,`e`.`CoverPrice2D`                        AS `audit_digital_coverprice2`
    ,`e`.`CoverPrice2DayD`                     AS `audit_digital_coverprice2day`
    ,`e`.`CoverPrice3D`                        AS `audit_digital_coverprice3`
    ,`e`.`CoverPrice3DayD`                     AS `audit_digital_coverprice3day`
    ,`e`.`CoverPrice4D`                        AS `audit_digital_coverprice4`
    ,`e`.`CoverPrice4DayD`                     AS `audit_digital_coverprice4day`
    ,`e`.`CoverPriceDayD`                      AS `audit_digital_coverpriceday`
    ,`e`.`ExcludedDatesD`                      AS `audit_digital_excludeddates`
    ,`e`.`inclAccomAirlinesSalesDigital`       AS `audit_digital_inclaccomairlinesales`
    ,`e`.`inclEducationalSalesDigital`         AS `audit_digital_incleducationalsales`
    ,`e`.`inclEventSalesDigital`               AS `audit_digital_incleventsales`
    ,`e`.`inclMultiplePublicationSalesDigital` AS `audit_digital_inclmultiplepublicationsales`
    ,`e`.`IssuesD`                             AS `audit_digital_issues`
    ,`e`.`IssuesAuditedD`                      AS `audit_digital_issuesaudited`
    ,`e`.`NonPublishingDatesD`                 AS `audit_digital_nonpublishingdates`
    ,`e`.`RemarksD`                            AS `audit_digital_remarks`
    ,`e`.`exclAustraliaOther`                  AS `audit_exclaustraliaother`
    ,`e`.`exclInExcess`                        AS `audit_exclinexcess`
    ,`e`.`ExcludedDates`                       AS `audit_excludeddates`
    ,`e`.`Exclusions`                          AS `audit_exclusions`
    ,`e`.`FrequencyID`                         AS `audit_frequencyid`
    ,`e`.`inclAccomAirlineSales`               AS `audit_inclaccomairlinesales`
    ,`e`.`inclEducationalSales`                AS `audit_incleducationalsales`
    ,`e`.`inclEventSales`                      AS `audit_incleventsales`
    ,`e`.`inclMultiplePublicationSales`        AS `audit_inclmultiplepublicationsales`
    ,`e`.`InExcess`                            AS `audit_inexcess`
    ,`e`.`Issues`                              AS `audit_issues`
    ,`e`.`IssuesAudited`                       AS `audit_issuesaudited`
    ,`e`.`NimsAvCopiesDelivered`               AS `audit_nimaveragecopiesdelivered`
    ,`e`.`NimsAvCopiesMailed`                  AS `audit_nimaveragecopiesmailed`
    ,`e`.`NimsAvCopiesPrinted`                 AS `audit_nimaveragecopiesprinted`
    ,`e`.`NIMCopiesDelivered`                  AS `audit_nimcopiesdelivered`
    ,`e`.`NIMCopiesMailed`                     AS `audit_nimcopiesmailed`
    ,`e`.`NIMCopiesPrinted`                    AS `audit_nimcopiesprinted`
    ,`e`.`NonPublishingDates`                  AS `audit_nonpublishingdates`
    ,`e`.`NZInExcess`                          AS `audit_nzinexcess`
    ,`e`.`NewZealand`                          AS `audit_nznps`
    ,`e`.`OCInExcess`                          AS `audit_ocinexcess`
    ,`e`.`OSMoney`                             AS `audit_osmoney`
    ,`e`.`OtherCountries`                      AS `audit_othercountries`
    , _utf8''                                  AS `audit_parentpublication`
    ,`e`.`AuditPeriod`                         AS `audit_period`
    ,`e`.`periodAdjustment`                    AS `audit_periodadjustment`
    ,`e`.`periodAdjustmentValue`               AS `audit_periodadjustmentvalue`
    , _utf8''                                  AS `audit_periodenddate`
    , _utf8''                                  AS `audit_periodstartdate`
    ,`e`.`PubID`                               AS `audit_pubid`
    ,`e`.`comments`                            AS `audit_remarks`
    ,`e`.`SpecialPublishingDay`                AS `audit_specialpublishingday`
    ,`e`.`stageid`                             AS `audit_stageid`
    ,`e`.`totalIssuesAudited`                  AS `audit_totalissuesaudited`
    ,`e`.`lAuditType`                          AS `audit_type`
    ,`e`.`iYear`                               AS `audit_year`
    ,`e`.`AuditorEmail`                        AS `deprecated_AuditorEmail`
    ,`e`.`AuditorName`                         AS `deprecated_AuditorName`
    ,`e`.`dateAuditorApproved`                 AS `deprecated_dateAuditorApproved`
    ,`e`.`dateSignatoryApproved`               AS `deprecated_dateSignatoryApproved`
    ,`e`.`dateSubmitted`                       AS `deprecated_dateSubmitted`
    ,`e`.`DayPublished`                        AS `deprecated_dayspublished`
    ,`e`.`FirstSignatoryEmail`                 AS `deprecated_FirstSignatoryEmail`
    ,`e`.`FirstSignatoryName`                  AS `deprecated_FirstSignatoryName`
    ,`e`.`FormStatus`                          AS `deprecated_FormStatus`
    ,`e`.`lodgementstatus`                     AS `deprecated_lodgementstatus`
    ,`e`.`lodgementtype`                       AS `deprecated_lodgementtype`
    ,`e`.`nPeriod`                             AS `deprecated_nPeriod`
    ,`e`.`nYear`                               AS `deprecated_nYear`
    ,`e`.`s2complete`                          AS `deprecated_s2complete`
    ,`e`.`s3complete`                          AS `deprecated_s3complete`
    ,`e`.`SecondSignatoryEmail`                AS `deprecated_SecondSignatoryEmail`
    ,`e`.`SecondSignatoryName`                 AS `deprecated_SecondSignatoryName`

...

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X