Vinzenz Mai: Tabellen existenz prüfen

Beitrag lesen

Hallo Tom,

Also suchen tue ich die Tabelle nicht direkt. Also wie schon gesagt ich möchte einfach nur prüfen ob eine bestimmte Tabelle vorhanden ist oder nicht.

Mit einem "show tables from datenbank where tablename = '$tablename'"

solltest Du zum Erfolg kommen. Man kann ab MySQL 5.x auch ein Select auf das Information_schema absetzen. Das setzt aber entsprechende Rechte voraus und ist etwas komplizierter ;-)

ich muss Dir widersprechen.

Weder setzt es mehr Rechte voraus als "SHOW TABLES", noch ist es komplizierter. Es ist einfacher, weil es ein ganz normales SELECT-Statement ist.

  
SELECT  
    TABLE_NAME  
FROM  
    INFORMATION_SCHEMA.TABLES  
WHERE  
    TABLE_NAME = '<gewünschter Tabellenname>'  

Dazu ist es noch deutlich portabler. Es spricht meiner Meinung nach wenig dafür, sich die proprietäre SHOW-Syntax anzutun. Für diesen Zweck definitiv *nichts*.

Ich zitiere aus dem entsprechenden Handbuchabschnitt:

<zitat>
    There is no difference between the privileges required for SHOW
    statements and those required to select information from
    INFORMATION_SCHEMA. In either case, you have to have some privilege
    on an object in order to see information about it.
</zitat>

Soviel zu "mehr Rechte".

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

- It conforms to Codd's rules. That is, all access is done on tables.
      - 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.
      - Migration is easier because every other DBMS does it this way.
</zitat>

Soviel zu den Vorteilen, die der Hersteller selbst sieht. Für mich sind diese Vorteile sehr überzeugend.

Energische Grüße

Vinzenz