I want to create a table that’s a cache of results from a view. Is there an easy way to automatically define the table from the view’s definition, or will I have to cobble it together from show create table view?
I want to create a table that’s a cache of results from a view.
Share
You can do
CREATE TABLE SELECTfrom the view to build it. That should duplicate the view’s structure as a new table containing all the view’s rows. Here’s the MySQL syntax reference for this statement.Note that you will want to be very explicit in your column selections. It isn’t advisable to do a
SELECT *from the source view. Make sure as well that you have aliases for any calculated or aggregate columns likeCOUNT(*), MAX(*), (col1 + col2), etc.