SQL Select: City Averagetemperature Date
SQL Select: City Averagetemperature Date
The SQL SELECT clause selects data from one or more database tables and/or views. In its basic form the SQL SELECT syntax looks like this:
AverageTemperature 22 C 21 C 20 C
SQL UNION
The SQL UNION clause merges the results of two or more SELECT SQL queries into one result set. When using SQL UNION, all the SQL expressions participating in the UNION must have the same structure (they have to have the same number of columns and same or compatible data types). You have to keep the column order of all unionized SQL SELECT expressions uniform, otherwise youll get an error. Here is an example of SQL UNION statement:
SELECT City, AverageTemperature, Date FROM Weather UNION ALL SELECT City, AverageTemperature, Date FROM WeatherArchive
The SQL TRUNCATE TABLE clause deletes all rows from a database table. Here is the SQL TRUNCATE TABLE syntax:
Insert into
The SQL INSERT INTO clause facilitates the process of inserting data into a SQL table. Here is how you can insert a new row into the Weather table, using SQL INSERT INTO:
INSERT INTO Weather (City, AverageTemperature, Date) VALUES ('Los Angeles', 20, '10/10/2005')
The result of the execution of the SQL INSERT INTO above will look like this:
AverageTemperature 22 C 21 C 20 C 20 C
You can produce the same result, with a slightly modified SQL INSERT INTO syntax:
AverageTemperature 22 C 21 C 20 C 20 C NULL
We've inserted a new row for Boston, but we haven't received the temperature value for 10/10/2005 that's why we didn't enter it.
The SQL AND & SQL OR keywords are used together with the SQL WHERE clause to join two or more search conditions specified in the WHERE clause. Let's use the weather table to illustrate how to use SQL AND & SQL OR keywords:
AverageTemperature 22 C 21 C
20 C 18 C 20 C 17 C
Here is how to select all rows where the city is either Washington or New York:
AverageTemperature 22 C 20 C 18 C 17 C
The following SQL statement using the SQL AND keyword will select all dates on which the average temperature in Washington was greater than 18 C:
SELECT Date FROM Weather WHERE City = 'Washington' AND AverageTemperature > 18
Here is the result of this SQL AND expression:
Date 10/10/2005
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 wont 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 theres 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.