Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Steve2106
Posting Yak Master
183 Posts |
Posted - 2013-02-04 : 06:17:16
|
Hi There,I have 2 databases on the same server and I am in need of having an exact copy of the custormers table.If a customer is added, updated or deleted in the customer table in database 1, I need it to be added, updated or deleted in the customer table in database 2How would I go about doing that?Thanks as always for your help, I appreciate your time.Best Regards,Steve |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-04 : 06:21:18
|
If a view is acceptable then the simplest thing is to create a view in the second databse (assuming of course, you are not going to update/delete/insert into the table in the second database) USE YourDB2GOCREATE VIEW dbo.YourViewNameASSELECT col1,col2,col3 FROM YourDB1.dbo.YourTableNameGO |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-04 : 06:30:57
|
Keep in mind that view is a virtual copy and wont store data in it unless you index it.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-02-04 : 06:40:20
|
If I am not mistaken, indexed views cannot be created across databases (requires schemabinding, and cross database schemabinding not being loved etc.). If the data does need to be persisted, use transactional replication as Visakh suggested. |
|
|
Steve2106
Posting Yak Master
183 Posts |
Posted - 2013-02-04 : 06:41:44
|
Hi Viskah,Thanks for the reply.I think this is a little beyond my access rights as it is a hosted server. I thought there maybe a trigger or something that I could use.Is there any other way to acheive what I need.Thanks again for your help.Best Regards,Steve |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-04 : 06:45:54
|
trigger is an overkill for this,esp if amount of DML operations on the table is large------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|