Upload
pongsakorn-u-chupala
View
4.888
Download
1
Tags:
Embed Size (px)
DESCRIPTION
For a session in #Exceedcamp7
Citation preview
INTRODUCTION TO DATABASE
With Microsoft Office Access 2007
Agenda
Getting to Know Database Basic of Microsoft Office Access 2007 Basic Operations of Database
Structured Query Language (SQL) CRUD Operations
Getting to Know Database
Definition of Database
Organized mechanism to store, manage and retrieve information Efficient Robust Stable
Arranged in tabular fashion Apparent relationship between
information The most important aspect Won’t be taught in this class :-(
Consists of a table, multiple fields and many columns
A Really Simple Database
Organization of Database
Tables Fields (Columns)
Has many types Primary Key (Optional)
Records (Rows, Entries)
When to Use Database? (1/3)Tasks AppropriatenessTransaction recordsLoggingShopping ListBlog/ForumMusic PlaylistMedia Library
Appropriate
Appropriate
Inappropriate
AppropriateInappropriate
Appropriate
When to Use Database? (2/3)
Transaction records
Logging Blog/Forum Media Library
Shopping list Music playlist
Appropriate Inappropriate
When to Use Database? (3/3) Managing mass amount of information Sharing Information between many users Manipulating complicatedly related
information Need security Desire organization
Under the Hood
Interface
Database Management System (DBMS)
Computer Resources
Structured Query Language
Microsoft Office Access 2007
Access Database File (*.accdb)
Infrastructure of Database
Implementations in which we are going to learn
Basic of Access 2007
Don’t panic! You’ll soon be familiar with it.
Microsoft Office Access 2007
Field Types (1/2)
Type ContainsText String of maximum
length at 255 characters
Memo StringNumber Number in multiple
format (Integer, Double, etc.)
Date/Time Date and timeCurrency Currency
Field Types (2/2)
Type ContainsAutoNumber Auto generated
number (Increment, Randomized)
Yes/No Boolean (True/False)OLE Object A certain type of file
(not mentioned)Hyperlink URLAttachment File
Basic Operations of Database
Structured Query Language (SQL)
Defines methods to manipulate database Attempt to request something from
Database is called Query Each formed SQL statement refer as SQL
Query Resembles natural language Has many standards
However, the basic part is still the same
CRUD
Create new tables and records Retrieve records from tables Update tables’ definition and record’s
data Delete existing tables and records
CRUD : Create
AutoNumber field must not be included Examples
INSERT INTO students (nisit_id, name, surname) VALUES (51052744, “Pongsakorn”, “U-chupala”);
INSERT INTO <table_name> (<field_list>)VALUES (<value_list>);
CRUD : Create - Example
nisit_id name surname
51051234 Steve Jobs
51052345 John Warnock
INSERT INTO students(nisit_id, name, surname)VALUES (51052744, “Pongsakorn”, “U-chupala”);
CRUD : Create - Example
nisit_id name surname
51051234 Steve Jobs
51052345 John Warnock
51052744 Pongsakorn U-chupala
INSERT INTO students(nisit_id, name, surname)VALUES (51052744, “Pongsakorn”, “U-chupala”);
CRUD : Create - Practice
Insert a record with every field specified
CRUD : Retrieve
Select which fields to retrieve Examples
SELECT field_1, field_2 FROM table_name … SELECT * FROM table_name …
SELECT <select_list> FROM <table_name>[ WHERE <search_condition> ][ ORDER BY <order_expression> [ ASC | DESC ] ];
CRUD : Retrieve
Available operators: =, <, >, <=, >=, <>
Modifiers: AND, OR, NOT, () Examples
… WHERE student_id=1 … … WHEHE (<cond1>) AND (<cond2>) …
SELECT <select_list> FROM <table_name>[ WHERE <search_condition> ][ ORDER BY <order_expression> [ ASC | DESC ] ];
CRUD : Retrieve
Sort results by order expression ascending (default) or descending
Expression can be chained together Examples
… ORDER BY date DESC … … ORDER BY name ASC, surname ASC …
SELECT <select_list> FROM <table_name>[ WHERE <search_condition> ][ ORDER BY <order_expression> [ ASC | DESC ] ];
CRUD : Retrieve - Example
nisit_id name surname height
51051234 Steve Jobs 160
51052345 John Warnock 165
51052744 Pongsakorn U-chupala 170
SELECT name, height FROM studentsWHERE height>160ORDER BY height DESC;
CRUD : Retrieve - Example
nisit_id name surname height
51051234 Steve Jobs 160
51052345 John Warnock 165
51052744 Pongsakorn U-chupala 170
SELECT name, height FROM studentsWHERE height>160ORDER BY height DESC;
name height
Pongsakorn 170
John 165
CRUD : Retrieve - Practice
Select every record, sort by STU_ID, ascending
Select name, surname and height of everyone shorter than 170
Select everyone heavier than 70, sort by height, descending
CRUD : Update
Update every record that match the search condition We usually use primary key for this
Examples UPDATE students SET name=“Knight”,
surname=“Baron” WHERE nisit_id=1;
UPDATE <table_name> SET <field_value_list>[ WHERE <search_condition> ];
CRUD : Update - Example
nisit_id name surname
51051234 Steve Jobs
51052345 John Warnock
51052744 Pongsakorn U-chupala
UPDATE students SET name=“Knight”, surname=“Baron”WHERE nisit_id=51052744;
CRUD : Update - Example
nisit_id name surname
51051234 Steve Jobs
51052345 John Warnock
51052744 Knight Baron
UPDATE students SET name=“Knight”, surname=“Baron”WHERE nisit_id=51052744;
CRUD : Update - Practice
Update the record that you’ve added earlier with different data
CRUD : Delete
Delete every record that match the search condition
Examples DELETE FROM students WHERE id=1 DELETE FROM students WHERE
(name=“Knight”) AND (surname=“Baron”);
DELETE FROM <table_name>WHERE <search_condition> ;
CRUD : Delete - Example
nisit_id name surname
51051234 Steve Jobs
51052345 John Warnock
51052744 Pongsakorn U-chupala
DELETE FROM studentsWHERE (nisit_id=51052345) OR (nisit_id=51052744);
CRUD : Delete - Example
nisit_id name surname
51051234 Steve Jobs
51052345 John Warnock
51052744 Pongsakorn U-chupala
DELETE FROM studentsWHERE (nisit_id=51052345) OR (nisit_id=51052744);
CRUD : Delete - Example
nisit_id name surname
51051234 Steve Jobs
DELETE FROM studentsWHERE (nisit_id=51052345) OR (nisit_id=51052744);
CRUD : Delete - Practice
Delete the record you’ve modified earlier
Conclusion
Review
Getting to know Database Definition Organization
Practicing with Access 2007 Database operations
SQL Syntax CRUD Operations
Please do not hesitate to ask
Any Questions?
Author: @KnightBaronBlog: http://aosekai.net/Email: [email protected]
Thank You!