Data Agent - SELECT from one table and insert into another - sql

Is there any type of product where I can write a SQL statement to select from one table and then insert into another database (The other database is out in the cloud). Also, it needs to be able to check to see if that record exists and then update the row if anything has changed. Then it will need to run every 10-30 minutes to check to see what has changed or if new records have been added.
The source database and the ending database have a different schema (if that matters?) I've been looking, but it seams that only products out there are ones that will just copy one table and insert into a table with the same schema.

Related

Inserting a single row from different databases

To start off we have two databases. One called TOk and the other called test2. test2 is a backup of TOk. A situation occurred in which a single row was deleted accidentally from the TOk database in the hazards table. I just want to know if there is a way to copy that record single row to another database. HazID is the unique identifier in that particular table so would something like. Both databases reside on the same instance.
INSERT INTO Tok.hazard.dbo *
Select * From Test2.hazard.dbo
Where HazID=(the specific ID of the missing record)
Is this close?
Basically expect the record to be copied back into the live database.

SQL - Record Every Statement That Updated Table

I am working on a database used by separate applications. One of these applications is updating two fields in a table but I can't work out what one and don't have the source code for all the applications.
I am wondering if it is possible to write a log (to another table or elsewhere) to what the last update statement made against the table in question was. E.g. to record all SQL that has attempted to update the table automatically...
create a trigger before update on this table. Also create a new table. In that trigger store values before and after update in to a newly created table

How to update a table copy in another database

I have two identical databases - one for development (DEV) and one for production (PROD) (both SQL Server 2008).
I have updated the contents of a certain table in DEV and now I want to sync the corresponding table in PROD.
I have not changed the table schema, only some the data inside the table (I have both changed existing rows and added some new rows).
How can I easily transfer the changes in DEV to the corresponding table in PROD?
Note, that the values in the automatic identity column mgiht not match exactly between the two tables. However, I know that I have only made changes to rows having the same value in another column.
Martin
If you don't want to use the replication, you can Create update, Insert and delete trigger in DEV database and update PROD by trigger.
or you can create view of DEV database table on the PROD database.

Import Export Wizard keep Identity, No Alter Table permissions

Basically, I am transferring data from one database table(A) to another database table(B).
Both databases have data except A gets updated daily and B needs to be updated with the current data in A. I would like to keep the identity column the same in both.
I try to run the wizard with delete previous data and the keep identity checked, but I get an error saying I don't have permission to alter table, so I am thinking that delete previous data truncates the table correct?
I then tried to use append table, but that complains about overwriting row with same identity value. Is there a way to ignore previous entries and only insert the new entries?
Sure, in your SELECT statement where you get data from table A, just select rows where A.ID is not equal to B.ID.
This functionality might work better with a trigger on table A or using transactional replication.

How to find when a row is inserted or updated in SQL Server table

I have a table in SQL Server but there is no column to show when the value is inserted into the table. And also I don't want to create a one.
Is there a way that I can find the time and date when some one has inserted a row into a SQL Server 2008 table or when it is updated?
If you don't want to modify your existing tables, the only way to go is to create another table to log the activities to. Then you can use ON INSERT / ON UPDATE triggers on the source tables and log the time and date of inserts and updates to the log table.
You can use On Insert and On Update Triggers in sql server 2005/2008 and your required fields are available in inserted and updated tables, but if you need to use this information later need to add a new table and log your information on to that!
I myself for doing such stuff like this always add 2 column to my tables
LastActivityBy relation to user table
and
LastActivityOn datetime
so you don't need to use any other table.
If you dont want to alter your existing schema, create a audit table and create trigger on source table to update audit table.