Trigger to copy data from a view to a table - T-SQL - sql

I'm wondering if there is any way to copy data from a view to a table in the same database. To be more clear, I have a view called AUTHORS_VIEW and a table called AUTHORS_TABLE. AUTHORS_VIEW takes data from others table in others databases.
I would copy new records in AUTHORS_VIEW not yet existing in AUTHORS_TABLE, update records in AUTHORS_VIEW not yet updated in AUTHORS_TABLE and remove record flagged as Removed in AUTHORS_VIEW from AUTHORS_TABLE.
Is it possible to achieve this with a trigger or others tool? I'm newbie with SQL Server.
This is my AUTHORS_VIEW (AUTHORS_TABLE is identical):

Related

Reflect the changes made in one table in sql to reflect automatically on another table

I have created a table in SQL by copying data from another table in a different database. How can I make the changes made in the old table get reflected in the new table automatically?
You can use a Trigger function to reflect the changes.
Refer this.
Given that you have access over the First table, Trigger would work fine.

PL/SQL Replicating a table with a trigger on Oracle DB

I have never used triggers in PLSQL before, but I am now supposed to make a trigger that replicates the table of one database, and creates a copy of this table in another database. I am using AQT(Advanced Query Tool) as DBMS, and i have 2 database connections, and I need to copy the table and or data from DB1 to DB2. It's only based on one table that I need replicated, following tutorialspoint I have concluded that it should look somewhat like this:
`
CREATE OR REPLACE TRIGGER db_transfer
AFTER DELETE OR INSERT OR UPDATE ON X
WHEN (NEW.ID > 0)
I don't think i need for each since i want a copy of the whole table, and the condition is supposed to trigger this replication of the DB table. Is this the right approach?
EDIT
For anyone who uses AQT, they have a feature under Create -> Trigger -> and then click on the relevant tables etc to create it.

Create a trigger for making a single audit table in sql server

How do I create a trigger in Microsoft SQL server to keep a track of all deleted data of any table existing in the database into a single audit table? I do not want to write trigger for each and every table in the database. There will only be once single audit table which keeps a track of all the deleted data of any table.
For example:
If a data is deleted from a person table, get all the data of that person table and store it in an XML format in an audit table
Please check my solution that I tried to describe at SQL Server Log Tool for Capturing Data Changes
The solution is build on creating trigger on selected tables dynamically to capture data changes (after insert, update, delete) and store those in a general table.
Then a job executes periodically and parses data captured and stored in this general table. After data is parsed it will be easier for humans to understand and see easily which table field is changed and its old and new values
I hope this proposed solution helps you for your own solution,

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

Method in SQL Server for making a copy of a table and refreshing it?

I'm trying to figure out if there's a method for copying the contents of a main schema into a table of another schema, and then, somehow updating that copy or "refreshing" the copy as the main schema gets updated.
For example:
schema "BBLEARN", has table users
SELECT * INTO SIS_temp_data.dbo.bb_users FROM BBLEARN.dbo.users
This selects and inserts 23k rows into the table bb_course_users in my placeholder schema SIS_temp_data.
Thing is, the users table in the BBLEARN schema gets updated on a constant basis, whether or not new users get added, or there are updates to accounts or disables or enables, etc. The main reason for copying the table into a temp table is for data integration purposes and is unrelated to the question at hand.
So, is there a method in SQL Server that will allow me to "update" my new table in the spare schema based on when the data in the main schema gets updated? Or do I just need to run a scheduled task that does a SELECT * INTO every few hours?
Thank you.
You could create a trigger which updates the spare table whenever an updated or insert is performed on the main schema
see http://msdn.microsoft.com/en-us/library/ms190227.aspx