How to synchronize view table to manual temporary table? - mysql

I have tables in database that consist of so many data records. I made view tables because I joined the tables. Then, when I tried to open the view tables, the time took so long because the tables had many data. So, I decided to make temporary table like this:
CREATE TABLE temp_ AS (SELECT * FROM view)
then, I want to synchronize the view and temporary table. As the example, when I tried to update the view table, then we're able to know that the temporary table has to change too because the temporary is synchronized with the view table. Maybe, it can be solved when the view's updated time > generated time than we have to update the table
I have table like this
I manually inserted the data records to both of that table. What may I do to synchronize them? Thanks in advance

Related

How expensive is creating a database view?

Right now, I'm altering a table with a crap ton of data, which is going to take weeks to run. In the meantime, I figured I'd create a new table to write to while this one is locked.
I can create an empty table and just write to this one, and check both tables when reading. Or I can create a copy of the current table and do all reads/writes from this copy for the next month.
It looks like copying the table is not the best solution. What about creating a view (just to read from) combining both tables?
CREATE VIEW MY_TABLE_VIEW AS
SELECT * FROM MY_TABLE
UNION ALL
SELECT * FROM MY_TABLE_COPY
Would creating the view be just as expensive as altering the original table? Should I instead just change all my table reads to UNION ALL the results from both tables?
Creating a view is a metadata-only operation. Views don't store any data. Querying the view will actually query the base table as if you ran the query in the view definition. So there's practically nothing to do to create the view. It only stores the query as metadata.

Does Truncating the Table Data Automatically Delete or truncate the View data?

I created a view using the Members table. If I truncate the Members table will it automatically truncate the view data?
A view is like a virtual table and does not have a Physical existence. A View is derived from an SQL Query which may pull data from a Single table or Multiple ones.
So when you do a query on a view, What it actually does is running the View Query on the background. So if you make any changes in the data on the Tables using the Underlying script, then the same will be effected automatically in the view

Is there any way to synchronize view and table in phpmyadmin?

I have a task to do synchronizing view with table in phpmyadmin. As example, I have a view table like this:
VIEW:
TABLE:
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
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.

working with temporary tables in Joomla 2.5

I am trying to use MySql temporary tables with my joomla site.
the problem is that whenever I query about the content of the table I get an empty result (except when using select statement in the same function where I create the table).
My questions are:
everytime I use $db = JFactory::getDBO() - do I create a new DB connection?
if so - how can I use temporary files?
if not - why don't I get the data of the temp table?
How can I create a temporary table that will remain until the user logs out?
You cannot use temporary tables like this, read the docs on temporary tables in MySQL here. The table will be deleted on each session, which will probably be each page load, possibly sooner, depending on how this is handled throughout Joomla.
If you want your temporary table to persist, you need to create normal table, not a temporary table...

Merge two database into a third one

I have two MySQL database k_db1 and k_db2 on a single server.
In k_db1, I have k_db1.table1 and k_db1.table2.
In k_db2, I have k_db2.table3 and k_db2.table4.
I want to create a third database k_db3 where I copy/paste tables of others databases.
It will result in k_db3.db1-table1, k_db3.db1-table2, k_db3.db2-table3, k_db3.db2-table4. I want to transfer data, indexes etc... and I don't want to delete k_db1 and k_db2 tables in the process. It must duplicate datas.
Do you know a way to do this just with SQL command?
Thanks in advance for your help.
You can try something like this:
DROP TABLE IF EXISTS k_db3.db1_table_1;
CREATE TABLE k_db3.db1_table_1 AS
SELECT * FROM db1.table_1;
Then you can recreate the indexes on the new table via ALTER TABLE statements.
Also I would avoid using - in table names.