Insert data into table from another table (from another connection) - mysql

I am curious if I can insert the data of a table from another connection to a table which i created.
I created the table GPS with the same column-names... etc. in the connection host-abc1.de
and now i want to fill in the data from another table (which also is called GPS and has the same columns, etc.) but this on another connection host-abc2.de
can I do something like this?
INSERT INTO host-abc1.de_NameOfSchema1_GPS, SELECT * FROM host-abc2.de_NameOfSchema2_GPS;
thank you very much for your help

You can create a Linked Server in order to work with data and objects from multiple sources.
The link below gives you detail about how to create a linked server and work with it -
https://learn.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-servers-sql-server-database-engine?view=sql-server-ver15

Related

Get logs of all update queries within database in mysql

I am looking to get all the update statements with old and new values within a database into one table.
For an example :
I have database name "users".
It contains four tables "primary_info","address_info","avtars","audit_logs"
Now, Whichever update statements executes on primary_info,address_info and avtars table that i need to log into audit logs table with below way.
ID, Table Name, Field_name,Old_value,New_value,Current Datetime
I know we can create triggers to manage such things.But i have database which contains more than 90 tables.So it won't help me to achieve by making trigger (update before) .
So is there any other way which i missed here ?
Thanks in advance.

MySql - Can I add a label to a table and retrieve using sql query

I have a requirement to provide a REST endpoint to create/delete tables for a privileged user.
When user makes a request to create table 'xyz', I create table with prefix "user_" and return response saying
'user_xyz' is created.
This way I know what tables are candidates for deletion when a request is made.
But I wish to create table "xyz" as requested by user and would like to add some label like "deletable" so that I can
query to find if a table can be deleted.
One option is adding a comment for table and but I have to query information_schema. Comment does not sound very correct.
Can this problem be solved using any other approach when I use MySql database.
I don't think you have much other options other than the one you suggest,
prefixing/suffixing table name
use table comment
create meta table with UserId(has the advantage of foreign keys)
and TableName fields (has the disadvantage of integrating the table
name with the actual very table as it can change without this
metatable being updated)
create separate schema for each user

Cant copy unique records from one database table to another?

Hi,
I am trying to copy unique records from a database table to another table of the same name but different database. The source database contains some records that are already present in the destination database, so those I dont need, only the other ones. Database destination is called "test" and the source database is "forums". The table name is store for both cases. I am using this query:
INSERT INTO test.store (cs_key, cs_value, cs_array, cs_updated,cs_rebuild)
SELECT DISTINCT cs_key, cs_value, cs_array, cs_updated,cs_rebuild
FROM forums.store
But I am getting many errors as I try to run this query. Why?
Thank you.

MySQL: Transfer duplicate records to another table, during INSERT `tablename` SELECT * FROM `data source`

I'm making a transition from MS Access into MySQL.
With Access, I can copy and paste data between tables, any duplicates will be automatically placed in the table paste_errors. How can I accomplish this in MySQL?
You can try creating a Trigger. Check out this SO post which will outline two ways to do it.

MySql TABLE data type

MS SQL Server has a TABLE data type which can be used in stored procedures,
Does anybody know if MySQL has an equivalent data type?
I've had a look over the docs but can't seem to find anything, so I presume it doesn't exist, but perhaps somebody has created a workaround
Neil,
MySQL has no such data type and I believe it is good that it doesn't. To achieve similar results, use CREATE TEMPORARY TABLE construction. Name clashes are avoided by having per connection temporary tables:
A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed. This means that two different connections can use the same temporary table name without conflicting with each other or with an existing non-TEMPORARY table of the same name. (The existing table is hidden until the temporary table is dropped.)
Hope it helps.