robguinness
robguinness

Reputation: 16656

Is there a way to create an SQL "alias"?

If there is a complicated query that I want to perform multiple times, is there a way to store it as an "alias"? For example, store:

SELECT 
    table_schema "Data Base Name", 
    SUM( data_length + index_length) / 1024 / 1024 "Data Base Size in MB" 
FROM information_schema.TABLES 
GROUP BY table_schema ;

as

GET_DB_SIZES

Is something like that possible???

Upvotes: 2

Views: 208

Answers (2)

Madhivanan
Madhivanan

Reputation: 13700

One option is to put resultset in a temporary table and use it further

Upvotes: -1

eggyal
eggyal

Reputation: 126035

Yes, create a VIEW:

CREATE VIEW GET_DB_SIZES AS <your query>;

Then you can:

SELECT * FROM GET_DB_SIZES;

Upvotes: 7

Related Questions