faecher:informatik:oberstufe:datenbanken:normalisierung:1_normalform:start

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige Überarbeitung Vorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
faecher:informatik:oberstufe:datenbanken:normalisierung:1_normalform:start [26.11.2020 10:42] sbelfaecher:informatik:oberstufe:datenbanken:normalisierung:1_normalform:start [08.02.2024 07:45] (aktuell) – alte Version wiederhergestellt (08.02.2024 08:40) Frank Schiebel
Zeile 67: Zeile 67:
  
 ++++ Lösung Schritt 2 | ++++ Lösung Schritt 2 |
 +<wrap hi>Achtung! Reihenfolge - warum?</wrap>
 <code sql> <code sql>
 UPDATE zahnarztbedarf SET plz = SUBSTRING_INDEX(TRIM(wohnort), ' ', 1) UPDATE zahnarztbedarf SET plz = SUBSTRING_INDEX(TRIM(wohnort), ' ', 1)
Zeile 72: Zeile 73:
 </code> </code>
  
 +++++
 +
 +++++ In einem (komplizierteren) Schritt | 
 +Man kann das auch direkt machen, indem man die folgende Anweisung entsprechend für alle 4 Informationen anpasst:
 +<code sql>
 +UPDATE zahnarztbedarf SET ort=SUBSTRING_INDEX(TRIM(SUBSTRING_INDEX(adresse, ',', -1)), ' ', -1); 
 +</code>
 ++++ ++++
  
Zeile 80: Zeile 88:
 ++++ Lösung |  ++++ Lösung | 
  
-4 neue Tabellenfelder + temporäres Feld:+4 neue Tabellenfelder: ''firma'', ''f_strasse'', ''f_plz'', ''f_ort''
  
 <code sql> <code sql>
Zeile 96: Zeile 104:
 Nun haben wir alles zusammen:  Nun haben wir alles zusammen: 
 <code sql > <code sql >
-UPDATE zahnarztbedarf t1 SET  +UPDATE zahnarztbedarf SET firma = SUBSTRING_INDEX(hersteller, ',', 1) 
-t1.firma = (SELECT SUBSTRING_INDEX(hersteller, ',', 1) FROM `zahnarztbedarf` t2 WHERE t2.id = t1.id ), +UPDATE zahnarztbedarf SET f_strasse = SUBSTRING_INDEX(SUBSTRING_INDEX(hersteller, ',' , 2), ',' , -1) 
-t1.f_strasse = (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(hersteller, ',' , 2), ',' , -1) FROM `zahnarztbedarf` t2 WHERE t2.id t1.id ), +UPDATE zahnarztbedarf SET f_ort = SUBSTRING_INDEX(hersteller, ',', -1) 
-t1.temp = (SELECT SUBSTRING_INDEX(hersteller, ',', -1) FROM `zahnarztbedarf` t2 WHERE t2.id = t1.id ) +UPDATE zahnarztbedarf SET f_plz = SUBSTRING_INDEX(TRIM(ort), ' ', 1) 
-WHERE t1.firma = '' +UPDATE zahnarztbedarf SET f_ort = SUBSTRING_INDEX(TRIM(ort), ' ', -1)
-</code> +
- +
-Jetzt noch analog zu oben PLZ und Ort aufteilen, TRIM nicht vergessen: +
- +
-<code sql> +
-UPDATE zahnarztbedarf t1 SET  +
-t1.f_ort (SELECT SUBSTRING_INDEX(TRIM(temp), ' ', -1) FROM `zahnarztbedarf` t2 WHERE t2.id t1.id ), +
-t1.f_plz = (SELECT SUBSTRING_INDEX(TRIM(temp), ' ', 1) FROM `zahnarztbedarf` t2 WHERE t2.id = t1.id ) +
-WHERE t1.f_plz = ''+
 </code> </code>
  
-Jetzt kann man ''hersteller'' und ''temp'' löschen.+Jetzt kann man ''hersteller'' löschen.
 ++++ ++++
  
  • faecher/informatik/oberstufe/datenbanken/normalisierung/1_normalform/start.1606387344.txt.gz
  • Zuletzt geändert: 26.11.2020 10:42
  • von sbel