Vinzenz Mai: Prüfung ob eine Spalte in MySQL Tabelle vorhanden ist

Beitrag lesen

Hallo

Jetzt, wo Du es schreibst...
Kein Einwand, wenn INFORMATION_SCHEMA vorhanden ist.
Das ist aber erst bei MySQL ab ? der Fall und in der XAMPP-Version ist es auch nicht zu finden. Oder bin ich schon wieder blind?

INFORMATION_SCHEMA gibt es in MySQL ab Version 5.0. Da MySQL 4.x nicht mehr unterstützt wird, gehe ich bei Nichtangabe einer Versionsnummer von der derzeit aktuellen Produktivversion von MySQL aus, das ist zur Zeit 5.0.x.
Von 5.1 existiert erst ein Release Candidate, vom Produktiveinsatz der 5.1 rät MySQL derzeit noch ab.

Vom Einsatz einer MySQL-Version älter als 5.0.12 rate ich insbesondere wegen der katastrophal fehlerhaften JOIN-Implementierung ab. Ältere MySQL-Versionen sind ein Grund für einen Providerwechsel, wobei das Upgrade der eigenen Anwendungen genau geplant sein will. Anwendungsneuentwicklung unter Berücksichtigung älterer Versionen als MySQL 5.0.12 halte ich für unsinnig (es sei denn, es wäre entsprechend lukrativ).

Selbstverständlich sollte INFORMATION_SCHEMA in XAMPP enthalten sein. Ich kann's nicht überprüfen, weil ich XAMPP nicht nutze.

SHOW COLUMNS
    FROM
        tabellenname
    LIKE
        'spaltenname'

gefällt mir dagegen sehr gut, weil es in allen mir bekannten MySQL-Versionen funktioniert und außerdem auch keine Probleme mit Case-Sensitivity hat.

Zu den Vorzügen von INFORMATION_SCHEMA und warum MySQL SHOW nicht eliminiert hat, kannst Du Dich im Handbuch informieren.

Warum ich INFORMATION_SCHEMA favorisiere, ich zitiere aus dem Handbuch:

<zitat>
     Using SELECT has these advantages, compared to SHOW:

* It conforms to Codd's rules. That is, all access is done on tables.
 [x] * Nobody needs to learn a new statement syntax. Because they already
       know how SELECT works, they only need to learn the object names.
     * The implementor need not worry about adding keywords.
     * There are millions of possible output variations, instead of just one.
       This provides more flexibility for applications that have varying
       requirements about what metadata they need.
 [x] * Migration is easier because every other DBMS does it this way.
</zitat>

Freundliche Grüße

Vinzenz