| Author |
Topic  |
|
|
Steve2106
Posting Yak Master
United Kingdom
149 Posts |
Posted - 02/04/2013 : 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 2
How 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
India
47189 Posts |
|
|
James K
Flowing Fount of Yak Knowledge
1530 Posts |
Posted - 02/04/2013 : 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 YourDB2
GO
CREATE VIEW dbo.YourViewName
AS
SELECT col1,col2,col3 FROM YourDB1.dbo.YourTableName
GO |
Edited by - James K on 02/04/2013 06:22:03 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47189 Posts |
Posted - 02/04/2013 : 06:30:57
|
Keep in mind that view is a virtual copy and wont store data in it unless you index it.
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
James K
Flowing Fount of Yak Knowledge
1530 Posts |
Posted - 02/04/2013 : 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
United Kingdom
149 Posts |
Posted - 02/04/2013 : 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
India
47189 Posts |
Posted - 02/04/2013 : 06:45:54
|
trigger is an overkill for this,esp if amount of DML operations on the table is large
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|