Friday, September 18, 2009

SQL Server 2008 : Overview

Your Data, Any Place, Any Time

SQL Server 2008 delivers on Microsoft’s Data Platform vision by helping your organization manage any data, any place, any time. Store data from structured, semi-structured, and unstructured documents, such as images and rich media, directly within the database. SQL Server 2008 delivers a rich set of integrated services that enable you to do more with your data such as query, search, synchronize, report, and analyze.

SQL Server 2008 provides the highest levels of security, reliability, and scalability for your business-critical applications. To take advantage of new opportunities in today's fast-moving business world, companies need the ability to create and deploy data-driven solutions quickly. SQL Server 2008 reduces time and cost of management and development of applications.

Access data from across your enterprise and provide control over your data no matter where it’s stored—from the largest servers within the data center to desktops to mobile devices. SQL Server 2008 provides a comprehensive platform that delivers intelligence where your users want it. Information workers can access data directly using the tools they use every day, such as the 2007 Microsoft Office system.

SQL Server 2008 enables data to be consumed from custom applications developed using Microsoft .NET and Visual Studio and from within service-oriented architectures (SOA) and business processes through Microsoft BizTalk Server.

SQL Server Model

Microsoft Data Platform Vision

Click image to enlarge

Solutions

Business Intelligence

Learn how SQL Server 2008 provides a scalable business intelligence platform optimized for data integration, reporting, and analysis, enabling organizations to deliver intelligence where users want it.

Virtualization and Server Consolidation

Server virtualization, also known as hardware virtualization, is a hot topic in the IT world because it can provide dramatic cost savings while enhancing a company’s agility.

Server Consolidation

Read about how SQL Server 2008 reduces hardware and maintenance costs by providing a flexible server consolidation solution with enterprise-class manageability and performance.

OLTP

Find out how SQL Server 2008 provides a scalable, high performance database engine for mission-critical applications that require the highest levels of availability and security, while reducing the total cost of ownership through enhanced enterprise-class manageability.

Data Warehousing

Discover how SQL Server 2008 provides a comprehensive and scalable data warehouse platform that enables organizations to integrate data into the data warehouse faster, scale and manage growing volumes of data and users, while delivering insights to all users.

Application Development

See how SQL Server 2008 is at the heart of a comprehensive data programmability platform that enables you to access and manipulate business-critical data from a variety of diverse devices, platforms, and data.

Wednesday, August 26, 2009

SQL Hosting

SQL Hosting is a hosting, which utilizes SQL database. There are many SQL databases used as SQL hosting backend, and the most common are MS SQL Server (2000 or 2005), MySQL, and MS Access. 

Why SQL Hosting?

You may ask what is the difference between a regular and SQL hosting. A regular hosting account, which doesn’t offer SQL databases usually uses static HTML pages to present its content. The disadvantage of that is that if you have a large website with many static web pages, any change in the common layout or functionality of the site becomes a nightmare. On the other hand if you use SQL hosting and have your entire web content in a database, you will utilize a server side technology like ASP, ASP.NET or PHP to get the content out of the SQL database and display it in the user’s browser. This way if you need to make layout or functional changes on your website you’ll simply change a single or handful of dynamic pages, which display your content. Utilizing SQL hosting gives you the advantage of separating your content of your website layout and functionality. 

Selecting SQL Hosting Provider

Selecting SQL Hosting provider doesn’t look like an easy task. How do you choose a SQL hosting, when there are so many SQL hosting providers on the market? The answer as in everything else is “perform due diligence”. There are several things to do when choosing SQL hosting: 
  • Do a search in web hosting directories and search engines and narrow down your choices to a handful of companies
  • Research the companies you have found – Find how long have they been in business, what does their customers say
  • Don’t go for the lowest SQL Hosting price – You get what you pay for
  • Make sure that the SQL Hosting company offers an unconditional money back guarantee for a minimum of 30 days – If you don’t like the service you can get your money back and walk away.

Harnessing the power of databases will get your website to a whole new level, that’s why getting SQL hosting is a must for every serious website. There is no need to spend a lot of money on SQL hosting either – you can get a quality SQL hosting for just $10-$15 per month.

Thursday, July 30, 2009

Learn the Modification of the Database

Deletion

- Delete all account records at the Kandy City branch.
delete * from account
where branch_name = ‘Kandy city’

- Delete all accounts at every branch located in Kandy.
delete * from account
where branch_name in (select branch_name
from branch
where branch_city=‘Kandy’)

Insertion

- Add a new tuple to account
insert into account
values (‘200116’, ‘Kandy City’,1200)

or equivalently
insert into account (branch_name, balance, account_number)
values (‘Kandy City’, 1200, ‘200116’)

- Add a new tuple to account with balance set to null
insert into account
values (‘100117’,‘Kandy City’, null)

Updates

- Increase all accounts with balances over Rs.1000 by 6%, all other accounts receive 5%.
- Write two update statements:
update account
set balance = balance *1.06
where balance > 1000
update account
set balance = balance * 1.05
where balance ≤ 1000

Sunday, July 19, 2009

Learn Aggregate Functions (Group by and Having clause)

- These functions operate on the multiset of values of a column of a relation, and return a value

avg: average value
min: minimum value
max: maximum value
sum: sum of values
count: number of tuples/values

- Find the average account balance at the Kandy city branch.
select avg (balance)
from account
where branch_name = ‘kandy City’

- Find the number of depositors in the bank.
select count (*)
from customer

- Find the number of tuples in the customer relation.
select count (distinct customer_name)
from depositor
(MS Access does not allow last one)

Aggregate Functions – Group By

- Find the number of depositors for each branch.
Note: Attributes in select clause outside of aggregate functions must appear in group by list

select branch_name, count (customer_name)
from depositor, account
where depositor.account_number = account.account_number
group by branch_name

Aggregate Functions – Having Clause

- Find the names of all branches where the average account balance is more than Rs.1,200.
Note: predicates in the having clause are applied after the formation of groups whereas predicates in the where clause are applied before forming groups

select branch_name, avg (balance)
from account
group by branch_name
having avg (balance) > 1200

Saturday, July 18, 2009

Learn Joined Relations in SQL

- Join operations take two relations and return as a result another relation.
- These additional operations are typically used as sub query
expressions in the from clause
- Join condition – defines which tuples in the two relations match,
and what attributes are present in the result of the join.
- Join type – defines how tuples in each relation that do not match
any tuple in the other relation (based on the join condition) are
treated.


Joined Relations – Data sets for Examples


loan inner join borrower on
loan.loan_number = borrower.loan_number

Learn Nested Subqueries and Set Comparison use in SQL

- SQL provides a mechanism for the nesting of sub queries.

- A sub query is a select-from-where
expression that is nested within another query.

- A common use of sub queries is to perform tests for set membership, set comparisons,
and set cardinality.

Example Query For Nested Sub queries

- Find all customers who have both an account and a loan at the bank.
select distinct customer_name
from borrower
where customer_name in (select customer_name from depositor)

- Find all customers who have a loan at the bank but do not have an account at the bank
select distinct customer-name
from borrower
where customer_name not in (select customer_name from depositor)

Set Comparison

- Find all branches that have greater assets than some branch
located in kandy.

select distinct T.branch_name
from branch as T, branch as S
where T.assets > S.assets and S.branch_city = ‘kandy’

- Same query using > some clause

select branch_name
from branch
where assets > some(select assets
from branch
where branch_city = ‘kandy’)

Thursday, June 25, 2009

Structured Query Language

What you will learn hear
- further DML commands
- DDL commands

Schema Used in Examples
- A Part of a Bank Database












Nested Nested Sub queries
- SQL provides a mechanism for the nesting of sub queries.
- A sub query is a select-from-where expression that is nested within another query.
- A common use of sub queries is to perform tests for set membership, set comparisons, and set cardinality.

Example Query


- Find all customers who have both an account and a loan at the bank.
select distinct customer_name
from borrower
where customer_name in (select customer_name
from depositor)

- Find all customers who have a loan at the bank but do not have an account at the bank
select distinct customer-name
from borrower
where customer_name not in (select customer_name
from depositor)

Set Comparison

- Find all branches that have greater assets than some branch located in kandy.
select distinct T.branch_name
from branch as T, branch as S
where T.assets > S.assets and S.branch_city = ‘kandy’

- Same query using > some clause
select branch_name
from branch
where assets > some (select assets
from branch
where branch_city = ‘kandy’)

Definition of Some Clause





















Definition of all Clause


Wednesday, June 17, 2009

Example For SQL

Schema Used in Examples
-
A Part of a Bank Database


Projecting Specific Columns From a Table

- Eg: Project all customer names, their streets & cities listed in the customer table
SELECT customer_name, customer_street,customer_city
FROM customer;


List List customer_city in the first column, and , customer_street in the second column in the second column

- We merely change the order of the projected attributes
SELECT customer_city, customer_street
FROM customer;

Notice that we have 2 sets of duplicate rows in the answer to our query. We
can eliminate these duplicate rows.



DISTINCT Keyword in SQL SELECT

- To Eliminate Duplicates in the Answer to our Query, use the DISTINCT Keyword in
SQL SELECT
SELECT distinct customer_city, customer_street
FROM customer;

- We have eliminated the duplicate rows in the answer to our query.


The Asterisk (*) in SELECT

- In Order to Project All Attributes: We Use The Asterisk ( * ) in SELECT
SELECT *
FROM customer;

is equivalent to
SELECT customer_name, customer_street, customer_city
FROM c
ustomer;


Project Specific Rows Which Satisfy a Predicate

SELECT *
FROM branch

WHERE branch_city = ‘kandy';
- In the “WHERE” clause, describe the predicate (i.e., condition which determines which rows are projected)
- E.g. Project all rows from branch which are branch city is ‘kandy’





Tuesday, June 16, 2009

Submitting SQL Queries to a DBMS


Submitting SQL Queries to a DBMS

- Generally, we submit SQL Queries to a DBMS, by illustrating the process for three different DBMS products:
Microsoft Access (we will discuss in this module) Microsoft SQL Server Oracle
- With some minor exceptions, the SQL will be the same for each of the above
Microsoft Access is supportive of SQL, but not as fully supportive as we might wish it to be

A part of a bank database: 6 Tables and Their Attribut
es


The Way of submitting SQL queries to DBMS
Data in the Tables:


step 1
Creating an SQL Query Using MS Access

- Select Queries Object, then “New”


step 2
Choose SQL View



step 3
Enter SQL Statements, then “Run” the Query


step 4
The Dynaset (Answer) to Query


Basic Structure of SQL and Key Clause

Basic Structure
- SQL is based on set and relational operations with certain modifications and enhancements
- A typical SQL query has the form:
select A1, A2, ..., An
from r1, r2, ..., rm
where P
Ais represent attributes
ris represent relations
P is a predicate.
-This query is equivalent to the relational algebra (to be discussed later) expression ∏A1, A2, ..., An(σP (r1 x r2 x ... x rm))
- The result of an SQL query is a relation.

Schema Used in Examples
- A Part of a Bank












The select Clause

- The select clause list the attributes desired in the result of a query (corresponds to the projection operation of the relational algebra)
- E.g. find the names of all branches in the loan relation
select branch_name
from loan
- In the “pure” relational algebra syntax, the query would be: ∏branch-name(loan)
- SQL does not permit the ‘-’ character in names,
Use, e.g., branch_name instead of branch-name in a real implementation
- SQL names are case insensitive, i.e. you can use capital or small letters.
- The general form of the SELECT clause
Select [distinct] attribute (s)
from table (s)
[where condition]
[group by attributes (s)]
[having condition]
[order by attributes (s)]
- SQL allows duplicates in relations as well as in query results
- To force the elimination of duplicates, insert the keyword distinct after select
- e.g Find the names of all branches in the loan relations, and remove duplicates
select distinct branch_name
from loan
- The keyword all specifies that duplicates not be removed.
select all branch_name
from loan
- An asterisk in the select clause denotes “all attributes”
select *
from loan
The select clause can contain arithmetic expression involving the operation +,-,*, and/,and
operating on constants or
attributes of tuples
- The query:
select loan_number,branch-number,amount*100
from loan
would return a relation which is the same as the loan relations,
except that the attribute amount is multiplied by 100

The where Clause
- The where clause specifies conditions that the result must satisfy (corresponds to the selection predicate of the relational algebra)
- e.g Get the customer names for customers in kandy
select customer_name
from customer
where customer_city=‘kandy’
-To find all loan number for loans made at the ‘colombo street-kandy’
with loan amounts greater than Rs.100000
select loan_number
from loan
where branch_name = ‘colombo street-kandy’ and amount >100000
- Comparison results can be combined using the logical connectives and, or, and not.
- Comparisons can be applied to results of arithmetic expressions.

The from Clause

- The from clause lists the relations involved in the query (corresponds to the Cartesian product operation of the relational algebra)
- Find the Cartesian product borrower x loan
select *
from borrower, loan
- Find the name, loan number and loan amount of all customers having a loan at the ‘colombo street-kandy’
select borrower.customer_name, borrower.loan_number, loan.amount
from borrower, loan
where borrower.loan_number = loan.loan_number and
loan.branch_name = ‘colombo street-kandy’

The Rename Operation
- The SQL allows renaming relations and attributes using the as
clause: old_name as new_name
- e.g Find the name, loan number and loan amount of all customers; rename the column name loan_number as loan_id.
select borrower.customer_name, borrower.loan_number as
loan_id, amount
from borrower, loan
where borrower.loan_number = loan.loan_number

Tuple Variables
- Tuple variables are defined in the from clause via the use of the as clause.
- e.g. Find the customer names and their loan numbers for all customers having a loan at some branch
select distinct T.branch_name
from branch as T, branch as S
where T.assets > S.assets and S.branch_city = ‘kandy’
- e.g. Find the names of all branches that have greater assets than some branch located in kandy
select customer_name, T.loan_number, S.amount
from borrower as T, loan as S
where T.loan_number = S.loan_number

String Operations
- SQL includes a string-matching operator for comparisons on character strings. Patterns are described using two special characters:
asterisk ( * ). The * character matches any substring.
question ( ? ). The ? character matches any character.
- Find the names of all customers whose street includes the sub string “Main”.
select customer_name
from customer
where customer_street like ‘*Main*’

Ordering the Display of Tuples
- List in alphabetic order the names of all customers having a loan in branch ‘colombo street-kandy’
select distinct customer_name
from borrower, loan
where borrower loan_number = loan.loan-number and
branch_name = ‘colombo street-kandy’
order by customer-name
- We may specify desc for descending order or asc for ascending order, for each attribute; ascending order is the default.
E.g. order by customer_name desc

DBMS Languages

Data Manipulation Language (DML)
- Used to specify database retrievals and updates
- DML commands (data sublanguage) can be embedded in a general-purpose programming language (C, COBOL etc)
- Alternatively, stand-alone DML commands can be applied directly (structure query language-SQL)
- select, insert, update, delete are the basic operations

Data Definition Language (DDL)
- Used by the DBA and database designers to specify the conceptual schema of a database
- the DDL is also used to define internal and external schemas (views)
- Create table, Alter table, drop table, create view, drop view are the basic operations