Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using SQL Server 2012.

I Need to create a Single Trigger From First_DataBase TableA to Second_DataBase TableB

When ever any modification done on TableA it'll affect the TableB

In this concept i am using Two DataBase

Whenever a row is inserted or updated or deleted in Table A, it should be affect the Table B.

Same Columns Name for TableA and TableB

How to handle this from a single trigger?
Posted
Comments
virusstorm 18-Jun-15 13:12pm    
I need to throw out a disclaimer first. This is design will lead to a great deal of trouble long term. First recommendation is not do this at the database level, but in the business layer of your application. If you can't do that, I would use a stored procedure. Lastly, and only as a last resort, I would use a trigger.

With the disclaimer out of the way, I need to know if these databases are on the same server and will always live on the same server.
Member 11775628 18-Jun-15 13:22pm    
In this concept DataBaseA having 40 tables, Just i am creating a New Database as DataBaseB, I am going to copy all the 40 tables from DataBaseA to DataBaseB and i am renaming the 40 Tables, After that i am going to Use Trigger Concept for INSERT\UPDATE\DELETE, and Whenever a row is inserted or updated or deleted in Table A (DataBaseA) , it should be affect the Table B(DataBaseB) ......
ZurdoDev 18-Jun-15 19:35pm    
1. Reply to comment so that the user is notified.
2. See Ben's comment. Use replication.
virusstorm 18-Jun-15 21:08pm    
Agreed with Ben. You should be using replication for this. Doing this through triggers is going spell lots of trouble for you. Take a look at this MSDN article and let us if you have any questions.

https://msdn.microsoft.com/en-us/library/ms151198%28v=sql.120%29.aspx
Ben J. Boyle 18-Jun-15 14:31pm    
Isn't this what replication was designed for? Why reinvent the wheel?

1 solution

Why don't you use data replication concept in this regard. Why because maintaining two databases in sync manually is not a good idea.

If you still want to do it through triggers, write a common stored procedure to handle the task in all three triggers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900