MySQL Forums
Forum List  »  German

SQL-Statement optimieren
Posted by: stefan chrobak
Date: December 06, 2016 09:53AM

Bin auf der Suche nach Optimierungs-Tips. Ich habe ein Datenbank ('codeigniter')
in der es nur Tabellen gibt, die über eine Indexspalte ('tabellenname_id') miteinander verbunden sind.

Hier ist mein Statement um alle Tabellen zu finden, die mit einer Tabelle, die
eine/mehrere Indexspalte hat, verknüpft sind.

Beispiel:
Tabelle b hat eine ID-Spalte
Tabelle a hat eine Indexspalte b_id
Die Suche gibt b aus wenn
TABELLENNAME = a

SELECT DISTINCT table_name AS tablename
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema COLLATE utf8_general_ci = 'codeigniter'
AND FIND_IN_SET (table_name COLLATE utf8_general_ci,(
SELECT DISTINCT GROUP_CONCAT( REPLACE( COLUMN_NAME, '_id', ''))
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema COLLATE utf8_general_ci = 'codeigniter'
AND table_name COLLATE utf8_general_ci = 'TABELLENNAME'
AND COLUMN_NAME COLLATE utf8_general_ci LIKE ('%%_id')))

Kann man das besser lösen?

Options: ReplyQuote


Subject
Views
Written By
Posted
SQL-Statement optimieren
953
December 06, 2016 09:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.