The most common data access method is structure query language (SQL). This language is designed to allow easy access to relational data. If you are familiar when set theory or Venn diagrams SQL will seem very intuitive. SQL allows you to quickly and simply combine relational data. Below is an example of a database containing two tables, customers and purchase order. The Customer table has customerid (the unique identifier for the customer), name (The customer’s name) and age (the customer’s age). The PurchaseOrder table has POID (the unique id for the purchase order), customerid (which refers back to the customer who made the purchase) and Purchase (what the purchase was). |
||||||||||||||||||||||||||||||||||||||||||||||||||||
Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT * FROM MyDataBase.Customer
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
ORDER BY
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT * FROM MyDataBase.Customer ORDER BY by age
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
WHERE
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT * FROM MyDataBase.Customer WHERE age = 18
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
INNER JOIN
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT * FROM MyDataBase.Customer INNER JOIN MyDataBase.PurchaseOrder ON Customer.CustomerID = PurchaseOrder.CustomerID
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
LEFT OUTER JOIN
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT * FROM MyDataBase.Customer LEFT OUTER JOIN MyDataBase.PurchaseOrder ON Customer.CustomerID = PurchaseOrder.CustomerID
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
GROUP BY
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
SELECT Name, count(*) as Orders FROM Customer INNER JOIN PurchaseOrder ON Customer.CustomerID = PurchaseOrder.CustomerID GROUP BY Name
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
UPDATE
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
UPDATE Customer SET Age = 26 WHERE CustomerID = 1
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
INSERT
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
INSERT INTO Customer Values (6, Terry , 50)
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
DELETE
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
DELETE FROM Customer WHERE CustomerID = 1
|
|