Wednesday, August 11, 2010

SQL Replication

SQL replication is a process for sharing/distributing data between different databases and synchronizing between those databases. You can use SQL replication to distribute data to a variety of network points like other database servers, mobile users, etc. You can perform the replication over many different kinds of networks and this won’t affect the end result.
In every SQL replication there are 2 main players called Publisher and Subscriber. The Publisher is the replication end point that supplies the data and the replication Subscriber is the replication end point that uses the data from the Publisher. Depending on the replication architecture a replication can have one or more Publishers and of course any replication will have one or more Subscribers.
MS SQL Server offers several main replication types. The Transactional replication is usually used when there’s need to integrate data from several different locations, offloading batch processing, and in data warehousing scenarios.
Another replication type is the Snapshot replication. The Snapshot replication is commonly performed when a full database refresh is appropriate or as a starting point for transactional or merge replications.
The third important SQL replication type is the Merge replication. The Merge replication is used whenever there is a possibility for a data conflicts across distributed server applications.

SQL Aggregate Functions

SQL aggregate functions are used to sum, count, get the average, get the minimum and get the maximum values from a column or from a sub-set of column values.

To count the rows in the Weather table we can use the SQL COUNT aggregate function:
SELECT COUNT(*)
FROM Weather

To get the average temperature for the Weather table use the AVG SQL aggregate function:
SELECT AVG(AverageTemperature)
FROM Weather

If you want to get the average temperature for a particular city you can do it this way:
SELECT AVG(AverageTemperature)
FROM Weather
WHERE City = 'New York'

To get the minimum value from a numeric table column, use the SQL MIN aggregate function:
SELECT MIN(AverageTemperature)
FROM Weather

To get the maximum value from a numeric table column, use the SQL MAX aggregate function:
SELECT MAX(AverageTemperature)
FROM Weather

Finally to sum up the values in the column use the SQL SUM aggregate function:
SELECT SUM(AverageTemperature)
FROM Weather

You can specify search criteria with the SQL WHERE clause for any of the above SQL aggregate functions.

No comments:

Post a Comment