Tải bản đầy đủ - 0 (trang)
5-13. Transferring a Complex Subset of Data Between Databases

5-13. Transferring a Complex Subset of Data Between Databases

Tải bản đầy đủ - 0trang

Chapter 5 ■ SQL Server Sources



2.



Since in this example the subscriber is the distributor, the wizard has correctly

inferred the instance to use it. Confirm with Next. The Snapshot Folder dialog box

appears.



3.



Enter a new network path for the snapshots if you are not willing to use the standard

SQL Server path. Click Next. The Distribution Database dialog box appears.



4.



Change any paths that you find unacceptable, and then change the Distribution

Database name if you prefer another name. Then click Next to display the Publishers

dialog box. This will have selected the current instance as a Publisher, so uncheck this

instance name. Next, click Add, and then select the instance that is publishing its data.



5.



Click Next to display the Distributor Password dialog box. Enter the Distributor

Password. Make sure that you note this!



6.



Click Next twice, and then click Finish to configure the Publisher. Hopefully, you see

the final dialog box confirming that the distribution has been configured successfully.



7.



You now need to configure the publication—the source data, in effect. In the

SQL Server instance that supplies the data, expand Replication, right-click Local

Publications, and select New Publication. Click Next to bypass the splash screen. The

Distributor dialog box appears.



8.



Select the Use the Following Server as the Distributor radio button. Click Add to

Select the Distributor. Confirm your choice. Click Next.



9.



Enter the Administrative password that you set (and noted) earlier. Click Next.



10.



Select the database containing the object(s) that you want to replicate. The

Publication Database dialog box lists all available databases. Click Next.



11.



Select Snapshot Replication from the Publication Type dialog box. Click Next.



12.



Select the Table(s) to publish.



13.



Click Next to display the Filter Table Rows dialog box.



14.



Click Next to display the Snapshot Agent dialog box. Check the Create a Snapshot

Immediately check box and the Schedule the Snapshot Agent check box (also

configure the schedule you require) if you wish for replication to be carried out on a

regular basis.



15.



Click Next. Select the security settings for the SQL Server Agent that the replication

will run.



16.



Click Next to display the Wizard Actions dialog box. Choose to create the publication

immediately, script the creation, or both!



17.



Click Next to display the final dialog box. Enter a name for the Publication.



18.



Click Finish to complete the process. If you have selected immediate creation of the

publication, the snapshot is created. A final dialog box shows you the status of the

process.



19.



You now need to set up the subscriber. Expand Replication, right-click Local

Subscriptions, and select New Subscription. Click Next to bypass the splash screen.

The Publication dialog box then allows you to select a publication. Select the SQL

Server instance that is publishing the data (you can browse for it if necessary). Click

Next.



270

www.it-ebooks.info



Chapter 5 ■ SQL Server Sources



20.



Select Run All Agents at the Distributor. Click Next.



21.



Select the database (you can create it from this dialog box if it does not already exist).

Click Next.



22.



Select the account under which Distribution will run. Click Next.



23.



Select a synchronization schedule. Click Next.



24.



Ensure that the Initialize check box is ticked so that the replication is initialized. Click

Next.



25.



Choose to create the subscription immediately, or to script the creation, or both. Click

Next.



26.



Verify that you have chosen all the options that you wanted. Click Finish.



27.



The subscription is created and the data is loaded into the subscriber database. You

should see the final dialog box confirming that all has run smoothly.



How It Works

The solution is an extremely succinct overview of snapshot replication. You did the following:

1.



Set up an SQL Server distributor on the source server.



2.



Defined the publisher (source) database and the source data (the publication).



3.



Ran the initial process to create a snapshot of the source data.



4.



Set up the destination (subscriber) database.



5.



Loaded the snapshot data into the destination.



One method of transferring data from one SQL Server instance to another that cannot be left out of the data

integration toolkit of any SQL developer or DBA is replication. As this is a vast subject with multiple ramifications,

I will not go into the full details of all the types of replication, and specifically all the management issues that

can arise. I can only refer you to Pro SQL Server 2005 Replication by Sujoy Paul (Apress, 2006), which covers the

ground in detail and with clarity. However, as an effective way of importing and updating data tables (and of

course subsets of data tables), replication is an efficient technology. If snapshot replication works, then it can

be a lifesaving technology. If it doesn’t, then it can consume hours or days of your life as you try to make it work.

However, that is another story.

I only covered snapshot replication because it can be claimed to be a data integration technique. For details

on transactional and merge replication, peer-to-peer replication, and managing replication, I suggest that you

consult some of the excellent material already written on the subject.

As far as terminology is concerned, mapping replication to data integration is not difficult. Essentially, the

data source is the replication publisher, and the data destination is the replication subscriber. The distributor can

be considered a part of the subscriber in this example, merely because I am presuming that this is a more “local”

instance. Of course, you can set up the distributor on the publisher, subscriber, or on a separate SQL Server

instance.

Assuming that you want to use this technique, just make sure that you are aware of the potential

drawbacks. Specifically, that locks are held during the replication process and all destination data is completely

overwritten.



271

www.it-ebooks.info



Chapter 5 ■ SQL Server Sources



5-14. Loading Data into SQL Server Azure Interactively

Problem

You want to load data directly into an SQL Azure database interactively.



Solution

Use SSMS and write a SELECT...INTO or INSERT INTO...SELECT query.

You can script data into an Azure table using SSMS just as you can into a traditional SQL Server table. All you

have to do is the following.

1.



Connect to the cloud-based database, as shown in Figure 5-8.



Figure 5-8.  Connecting to SQL Server Azure

2.



You can then run a standard INSERT INTO...VALUES statement to insert data in a

query window.



How It Works

As we are living in interesting times, we are facing interesting new challenges, and using cloud-hosted databases

is one of the most exciting new things to happen in quite a while. So how does SQL Server manage this new

opportunity?

The answer is “with considerable ease”—providing that you are using SQL Server 2008 R2 or later. If you are

using SQL Server 2008, then you can use only SSIS.



272

www.it-ebooks.info



Chapter 5 ■ SQL Server Sources



Describing how to set up an SQL Server Azure database is beyond the scope of this book; but presuming

that you have an Azure database subscription, and that you have defined the required firewall rules to allow your

workstation to communicate with SQL Server Azure, then you can load data into a cloud-hosted database almost

as if it were on your local server.

Because you will meet them frequently in these recipes, I prefer to explain the connection string parameters

of the SQL Server Azure database. This helps you understand the various code snippets and screen captures that

you encounter. The SQL Azure connection parameters are provided in Table 5-7.

Table 5-7.  SQL Azure Connection Parameters



Parameter



Element



User



MeForPrimeMinister



Server



recipes.database.windows.net



Password



Gubbins



Database



CarSales



Hints, Tips, and Traps





SQL Server Azure only supports SQL Server authentication.







You must use the fully qualified DNS name as it is given in the Azure Management Portal.



5-15. Loading Data into SQL Server Azure as Part of a Regular

ETL Process

Problem

You want to load data SQL Server Azure as part of a regular ETL process.



Solution

Use SSIS to load data into Azure. This is done as follows:

1.



Create a new SSIS package, name it appropriately, and add a new OLEDB connection

manager to your source database (CarSales in this recipe). Name it Source_OLEDB.



2.



Add a new ADO.NET connection manager named Azure_ADONET. Configure it to

connect to your SQL Server Azure database, as shown in Figure 5-9.



273

www.it-ebooks.info



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

5-13. Transferring a Complex Subset of Data Between Databases

Tải bản đầy đủ ngay(0 tr)

×