SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Mirror a Table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Steve2106
Posting Yak Master

United Kingdom
166 Posts

Posted - 02/04/2013 :  06:17:16  Show Profile  Reply with Quote
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
52317 Posts

Posted - 02/04/2013 :  06:21:00  Show Profile  Reply with Quote
sounds like transactional replication to me

see

http://www.databasejournal.com/features/mssql/article.php/1438201/Setting-Up-Transactional-Replication-A-Step-by-step-Guide.htm

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3588 Posts

Posted - 02/04/2013 :  06:21:18  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/04/2013 :  06:30:57  Show Profile  Reply with Quote
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/

Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3588 Posts

Posted - 02/04/2013 :  06:40:20  Show Profile  Reply with Quote
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.
Go to Top of Page

Steve2106
Posting Yak Master

United Kingdom
166 Posts

Posted - 02/04/2013 :  06:41:44  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/04/2013 :  06:45:54  Show Profile  Reply with Quote
trigger is an overkill for this,esp if amount of DML operations on the table is large

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.22 seconds. Powered By: Snitz Forums 2000