Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 20764

How to write a update,delete trigger in sqlserver2008

$
0
0
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

Viewing all articles
Browse latest Browse all 20764

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>