0

I have a task to do synchronizing view with table in phpmyadmin. As example, I have a view table like this:

VIEW:

enter image description here

TABLE:

enter image description here

the data records of table is same as view. I copy the data from view to table using

CREATE TABLE tablename AS (SELECT * FROM viewname)

I want to synchronize them. As example, when view is updated then table will be updated too. The meaning of view's updating is like editing the view then I import the view again by deleting the old one. Is there any way to do that? I want to synchronize the view and the table because the time took so long when I open the view. So I made table which is same as view so that I'm able to open it faster. Thanks in advance

r34627673
  • 293
  • 3
  • 18
  • What do you mean with "when view is changed"? – Per Enström May 08 '17 at 08:16
  • 1
    A **view** is a Logical view on table(s), they have no explizit data. – Jens May 08 '17 at 08:17
  • 1
    Also read this: http://stackoverflow.com/questions/6015175/difference-between-view-and-table-in-sql – Jens May 08 '17 at 08:18
  • I mean "when the view is updated" @PerEnström – r34627673 May 08 '17 at 08:18
  • A view is not updated! A View is basically a canned query that runs to pick up data from 1 or more tables. Its the tables that are updated. Once the tables are updated you run the View to pick up the changes made to the tables and look at the data afresh – RiggsFolly May 08 '17 at 08:24
  • 2
    I think you need to explain WHY you are doing this, if you indeed are copying view data from table A to a table B. – Per Enström May 08 '17 at 08:31
  • phpmyadmin is just a GUI. Any changes you would like to do will be done in MySQL. Once you manage to explain what on Earth you would like to do, we may be able to help with that. – Shadow May 08 '17 at 08:35
  • So what is the alternative way so that I can open the view faster? I copy view into a table so that I can open the table quickly @RiggsFolly – r34627673 May 08 '17 at 10:22
  • But as soon as you fix the view results into a table, they run the risk of being Out Of Date – RiggsFolly May 08 '17 at 10:24
  • Yes, you're right. When the table is out of date, then I update the view by editing the view then import it again. So I need to synchronize the table @RiggsFolly or is there any alternative way to open the view faster? – r34627673 May 08 '17 at 10:29
  • No idea what your view is doing! But start by checking that it is using indexes correctly – RiggsFolly May 08 '17 at 10:34

1 Answers1

2

VIEW in MySQL is a virtual table or logical view of a table as mentioned by Jens that has no data stored on it like a table.

Instead, it fetches the values directly from the table. The values in VIEW changes when the values from the table it fetches changes.

Therefore you will need to sync between the tables and not between view and table.