MySQL har flera metoder för att kontrollera om en tabell finns. Här är fem vanliga sätt.
1. sys.table_exists()
CALL sys.table_exists('Music', 'Albums', @table_type); SELECT @table_type;
Resultatet kan vara BASE TABLE, TEMPORARY eller VIEW.
2. information_schema.TABLES
SELECT TABLE_NAME, TABLE_TYPE FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'music' AND TABLE_NAME = 'Artists';
3. SHOW TABLES
SHOW FULL TABLES WHERE Table_Type LIKE 'BASE TABLE';
4. SHOW TABLE STATUS
SHOW TABLE STATUS FROM Music WHERE Name = 'Albums';
5. mysqlshow
mysqlshow --user root --password music
Om du bara vill skapa tabellen när den saknas kan du använda CREATE TABLE IF NOT EXISTS.