hii to all,
I have a requirement that,i need to migrate or copy the data between two tables.Actually i have two tables Mainlog(in user db) & Sparelog(in users2 db) with same structure present in different databases,now if any data is inserted into mainlog table it should automatically copy to sparelog table, i have done this by writing some insert trigger like below:
<pre lang="SQL">CREATE TRIGGER InsertLogRecords
ON mainlog FOR INSERT
AS
BEGIN
SET NOCOUNT ON
IF EXISTS(SELECT * FROM mainlog)
INSERT INTO users2.dbo.sparelog
SELECT * FROM inserted
ELSE
INSERT INTO users2.dbo.sparelog
SELECT * FROM inserted
END</pre>
The above trigger is working fine and copying the data to sparelog table automatically when ever any data is inserted.Now even i want the same action when update and delete operation is performed to mainlog table the same update,delete action should automatically reflect to sparelog table.Please guide how can i do this with single trigger or with two triggers like update,delete triggers,please try to help me with code.thanks in advance
I have a requirement that,i need to migrate or copy the data between two tables.Actually i have two tables Mainlog(in user db) & Sparelog(in users2 db) with same structure present in different databases,now if any data is inserted into mainlog table it should automatically copy to sparelog table, i have done this by writing some insert trigger like below:
<pre lang="SQL">CREATE TRIGGER InsertLogRecords
ON mainlog FOR INSERT
AS
BEGIN
SET NOCOUNT ON
IF EXISTS(SELECT * FROM mainlog)
INSERT INTO users2.dbo.sparelog
SELECT * FROM inserted
ELSE
INSERT INTO users2.dbo.sparelog
SELECT * FROM inserted
END</pre>
The above trigger is working fine and copying the data to sparelog table automatically when ever any data is inserted.Now even i want the same action when update and delete operation is performed to mainlog table the same update,delete action should automatically reflect to sparelog table.Please guide how can i do this with single trigger or with two triggers like update,delete triggers,please try to help me with code.thanks in advance