2009年4月4日星期六

Introduce of SQL

SQL, which is a database computer language, is designed for manage and retrieve DBMS. ANSI and ISO standardize SQL. SQL allows the retrieval, updating, insertion, and deletion of data. SQL was first developed at IBM by by Andrew Richardson, Donald C. Messerly and Raymond F. Boyce in the early 1970s. It's revised manay times during the pass 30 years and it's still developing today.

SQL standard includes many parts:
SQL/Foundation. This part contains the basic elements of the language.
SQL/CLI. This part includes independent mandatory features.
SQL/PSM. This part includes optional features.
Elements of SQL lanaguage:
Clauses. It contains components of statement and queries.
Expressions. It produces tables and values.
Predicates. It is used to limit the statement and queries.
Queries. Get the data based on standard.
Statements. It controls transactions, flow of program, sessions, etc.

Querries:
It's the most common operation in database. There're 5 clauses: From, Where, Group by, Having, Order by. Querries are widely used in many fields, for example, data manipulation, transaction controls, data definition, data control, etc.
What can SQL do?
1. Run queries based on a database
2. Get data from a database
3. Enter records to database
4. Update records
5. Delete records
6. Set precedures, views, permit on tables


SQL Diagrams 2004 screenshot

There're some SQL example as follow:
1. If you want to update a sales person, his name is Mike, his customers are in Quebec
You should use command: UPDATE customers SET salesperson = "Mike" WHERE state = "QC"
2. If you want to know what did your customers buy
You should use command: SELECT DISTINCT customers.customer_id, customers.customer_name
FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id
3. If you want to know the customers who never ordered from you
You should use command: SELECT customers.* FROM customers LEFT JOIN orders ON customers.customer_id = orders.customer_id WHERE orders.customer_id IS NULL
4. If you want to copy your customer's data from one table to another
You should use command: INSERT INTO customers(customer_id, customer_name)
SELECT cus_key, cus_name
FROM jimmyscustomers WHERE customer_name LIKE 'B%'

References

Refsnes Data (2009) Introduction to SQL

http://www.w3schools.com/SQL/sql_intro.asp

Wikipedia (3 April 2009) SQL
http://en.wikipedia.org/wiki/SQL

没有评论:

发表评论