Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Triggers Examples


Triggers Examples

Author
Message
ganesh.khuspe_v
ganesh.khuspe_v
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 9
Thanx for the reply. I did the same on the same server but its not working. Actually i wanted to do the same on two different Sql server. My one Database Server is server1 and another one is Server2.One database present on server1 and other is on server2.Following is My query.

CREATE TRIGGER trigger1 ON Document after Update AS
begin
INSERT INTO [TEST].[dbo].Document_Log(ID,InwardID,RetrievalID,UnitID,DepartmentID,DocumentType,
   DocumentCriticality,AdditionalInfo1,AdditionalInfo2,AdditionalInfo3,DocAccRelated,AccountNumber,
   CustomerName,TransactionDateFrom,TransactionDateTo,DocCategory,DocClosingDate,ProposedDestructionDate,
   CheckerDestructionDate,
   SuperCheckerDestructionDate,
   DocumentStatusID,
   DocumentName,
   Location,
   StorageVendor,
   BoxBarcode,
   IsRefiled,
   ReinventoryStatus,
   DateofDispatch,
   AdditionalDispatchDetails,
   FileBarcode,
   InwardDate,
   RetrievalDate,
   LostStatus,
CreatedOn,
   CreatedBy,
   UpdatedOn,
   UpdatedBy) ---- this is required otherwise will get error.
SELECT ID,InwardID,RetrievalID,UnitID,DepartmentID,DocumentType,
   DocumentCriticality,AdditionalInfo1,AdditionalInfo2,AdditionalInfo3,DocAccRelated,AccountNumber,
   CustomerName,TransactionDateFrom,TransactionDateTo,DocCategory,DocClosingDate,ProposedDestructionDate,
   CheckerDestructionDate,
   SuperCheckerDestructionDate,
   DocumentStatusID,
   DocumentName,
   Location,
   StorageVendor,
   BoxBarcode,
   IsRefiled,
   ReinventoryStatus,
   DateofDispatch,
   AdditionalDispatchDetails,
   FileBarcode,
   InwardDate,
   RetrievalDate,
   LostStatus,
CreatedOn,
   CreatedBy,
   UpdatedOn,
   UpdatedBy
from inserted
end

I m getting an error as

Msg 208, Level 16, State 1, Procedure trigger1, Line 4
Invalid object name 'TEST.Document_Log'.


I tried this on the same server by making replica of database2 on the same server. But same is not working on one server then how it will work on different server. Please Suggest me something so that i can do the same on two different server.

Thanks...
ganesh.khuspe_v
ganesh.khuspe_v
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 9
Thanx for the reply. I did the same on the same server but its not working. Actually i wanted to do the same on two different Sql server. My one Database Server is server1 and another one is Server2.One database present on server1 and other is on server2.Following is My query.

CREATE TRIGGER trigger1 ON Document after Update AS
begin
INSERT INTO [TEST].[dbo].Document_Log(ID,InwardID,RetrievalID,UnitID,DepartmentID,DocumentType,
   DocumentCriticality,AdditionalInfo1,AdditionalInfo2,AdditionalInfo3,DocAccRelated,AccountNumber,
   CustomerName,TransactionDateFrom,TransactionDateTo,DocCategory,DocClosingDate,ProposedDestructionDate,
   CheckerDestructionDate,
   SuperCheckerDestructionDate,
   DocumentStatusID,
   DocumentName,
   Location,
   StorageVendor,
   BoxBarcode,
   IsRefiled,
   ReinventoryStatus,
   DateofDispatch,
   AdditionalDispatchDetails,
   FileBarcode,
   InwardDate,
   RetrievalDate,
   LostStatus,
CreatedOn,
   CreatedBy,
   UpdatedOn,
   UpdatedBy) ---- this is required otherwise will get error.
SELECT ID,InwardID,RetrievalID,UnitID,DepartmentID,DocumentType,
   DocumentCriticality,AdditionalInfo1,AdditionalInfo2,AdditionalInfo3,DocAccRelated,AccountNumber,
   CustomerName,TransactionDateFrom,TransactionDateTo,DocCategory,DocClosingDate,ProposedDestructionDate,
   CheckerDestructionDate,
   SuperCheckerDestructionDate,
   DocumentStatusID,
   DocumentName,
   Location,
   StorageVendor,
   BoxBarcode,
   IsRefiled,
   ReinventoryStatus,
   DateofDispatch,
   AdditionalDispatchDetails,
   FileBarcode,
   InwardDate,
   RetrievalDate,
   LostStatus,
CreatedOn,
   CreatedBy,
   UpdatedOn,
   UpdatedBy
from inserted
end

I m getting an error as

Msg 208, Level 16, State 1, Procedure trigger1, Line 4
Invalid object name 'TEST.Document_Log'.


I tried this on the same server by making replica of database2 on the same server. But same is not working on one server then how it will work on different server. Please Suggest me something so that i can do the same on two different server.

Thanks...
twin.devil
twin.devil
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1376 Visits: 2596
If you want to move the data from Server1 to Server2, then you need a connect to that server.

1) Create a link to Server2 link
2) Create a SYNONYM

CREATE SYNONYM myTable2 FOR
[Server2].[DataBase2].dbo.Table2;



3) Change your Query like this

INSERT INTO MyTable2(ID,InwardID,RetrievalID,UnitID,DepartmentID,DocumentType,
DocumentCriticality,AdditionalInfo1,AdditionalInfo2,AdditionalInfo3,DocAccRelated,AccountNumber,
CustomerName,TransactionDateFrom,TransactionDateTo,DocCategory,DocClosingDate,ProposedDestructionDate,
CheckerDestructionDate,
SuperCheckerDestructionDate,
DocumentStatusID,
DocumentName,
Location,
StorageVendor,
BoxBarcode,
IsRefiled,
ReinventoryStatus,
DateofDispatch,
AdditionalDispatchDetails,
FileBarcode,
InwardDate,
RetrievalDate,
LostStatus,
CreatedOn,
CreatedBy,
UpdatedOn,
UpdatedBy) ---- this is required otherwise will get error.
SELECT ID,InwardID,RetrievalID,UnitID,DepartmentID,DocumentType,
DocumentCriticality,AdditionalInfo1,AdditionalInfo2,AdditionalInfo3,DocAccRelated,AccountNumber,
CustomerName,TransactionDateFrom,TransactionDateTo,DocCategory,DocClosingDate,ProposedDestructionDate,
CheckerDestructionDate,
SuperCheckerDestructionDate,
DocumentStatusID,
DocumentName,
Location,
StorageVendor,
BoxBarcode,
IsRefiled,
ReinventoryStatus,
DateofDispatch,
AdditionalDispatchDetails,
FileBarcode,
InwardDate,
RetrievalDate,
LostStatus,
CreatedOn,
CreatedBy,
UpdatedOn,
UpdatedBy
from inserted



But i wont recommend using this kind of logic in the trigger. If you are using Store Procedure for
C.R.U.D operation, then i would suggest to bring this logic into a store Procedure.(If you need a immediate result)

If you just storing this information for logging purposes i would suggest the following:

1) Create a Log Dump table in Database1.
2) Create a SSIS package to move the data from Server1 to server 2 and Truncate the Dump Table in Database1.
3) Create a SQL JOB, link it with SSIS package, and Set the desired Interval.


Hope it helps.
ganesh.khuspe_v
ganesh.khuspe_v
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 9
I dont have any idea about SSIS package. I tried to make new Flat file in SSIS but not worked. Can u please give me practical example.???
twin.devil
twin.devil
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1376 Visits: 2596
You can get your hands dirty in SSIS. Following is the link for Stairway to Integration Services by Andy Leonard

As per your current case, you just need to move the data from Source Table to the Destination Table.

Just like importing/Export Wizard in SQL SEVER. If you want to use the SSIS Approach you need to the following

1) Create a Log Table in Server1.Database1 and use this table in the Trigger.
2) Create a replica Log Table on Server2.Database2.
3) For kick start sample ssis package is attached. (change the file extention from txt to dtsx).

Hope it helps.
Attachments
pkgDumpData.txt (2 views, 38.00 KB)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search