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


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



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.


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.


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

Password. Make sure that you note this!


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.


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.


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

Select the Distributor. Confirm your choice. Click Next.


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


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

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


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


Select the Table(s) to publish.


Click Next to display the Filter Table Rows dialog box.


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.


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

will run.


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

immediately, script the creation, or both!


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


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



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




Chapter 5 ■ SQL Server Sources


Select Run All Agents at the Distributor. Click Next.


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

Click Next.


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


Select a synchronization schedule. Click Next.


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



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



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


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:


Set up an SQL Server distributor on the source server.


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


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


Set up the destination (subscriber) database.


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


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




Chapter 5 ■ SQL Server Sources

5-14. Loading Data into SQL Server Azure Interactively


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


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.


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

Figure 5-8.  Connecting to SQL Server Azure


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


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.



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











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


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


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


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.


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.



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)