Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Triggers Examples Expand / Collapse
Author
Message
Posted Wednesday, April 2, 2014 11:23 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, April 3, 2014 4:32 AM
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...
Post #1557815
Posted Wednesday, April 2, 2014 11:29 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, April 3, 2014 4:32 AM
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...
Post #1557816
Posted Thursday, April 3, 2014 12:40 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 4:13 AM
Points: 747, Visits: 1,315
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.






Post #1557834
Posted Thursday, April 3, 2014 2:58 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, April 3, 2014 4:32 AM
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.???
Post #1557868
Posted Thursday, April 3, 2014 4:32 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 4:13 AM
Points: 747, Visits: 1,315
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.




  Post Attachments 
pkgDumpData.txt (2 views, 38.28 KB)
Post #1557896
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse