40
INTRODUCTION TO DATABASE With Microsoft Office Access 2007

Introduction to database

Embed Size (px)

DESCRIPTION

For a session in #Exceedcamp7

Citation preview

Page 1: Introduction to database

INTRODUCTION TO DATABASE

With Microsoft Office Access 2007

Page 2: Introduction to database

Agenda

Getting to Know Database Basic of Microsoft Office Access 2007 Basic Operations of Database

Structured Query Language (SQL) CRUD Operations

Page 3: Introduction to database

Getting to Know Database

Page 4: Introduction to 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 :-(

Page 5: Introduction to database

Consists of a table, multiple fields and many columns

A Really Simple Database

Page 6: Introduction to database

Organization of Database

Tables Fields (Columns)

Has many types Primary Key (Optional)

Records (Rows, Entries)

Page 7: Introduction to database

When to Use Database? (1/3)Tasks AppropriatenessTransaction recordsLoggingShopping ListBlog/ForumMusic PlaylistMedia Library

Appropriate

Appropriate

Inappropriate

AppropriateInappropriate

Appropriate

Page 8: Introduction to database

When to Use Database? (2/3)

Transaction records

Logging Blog/Forum Media Library

Shopping list Music playlist

Appropriate Inappropriate

Page 9: Introduction to database

When to Use Database? (3/3) Managing mass amount of information Sharing Information between many users Manipulating complicatedly related

information Need security Desire organization

Page 10: Introduction to database

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

Page 11: Introduction to database

Basic of Access 2007

Page 12: Introduction to database

Don’t panic! You’ll soon be familiar with it.

Microsoft Office Access 2007

Page 13: Introduction to database

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

Page 14: Introduction to database

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

Page 15: Introduction to database

Basic Operations of Database

Page 16: Introduction to 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

Page 17: Introduction to database

CRUD

Create new tables and records Retrieve records from tables Update tables’ definition and record’s

data Delete existing tables and records

Page 18: Introduction to database

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>);

Page 19: Introduction to database

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”);

Page 20: Introduction to database

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”);

Page 21: Introduction to database

CRUD : Create - Practice

Insert a record with every field specified

Page 22: Introduction to database

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 ] ];

Page 23: Introduction to database

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 ] ];

Page 24: Introduction to database

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 ] ];

Page 25: Introduction to database

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;

Page 26: Introduction to database

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

Page 27: Introduction to database

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

Page 28: Introduction to database

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> ];

Page 29: Introduction to database

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;

Page 30: Introduction to database

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;

Page 31: Introduction to database

CRUD : Update - Practice

Update the record that you’ve added earlier with different data

Page 32: Introduction to database

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> ;

Page 33: Introduction to database

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);

Page 34: Introduction to database

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);

Page 35: Introduction to database

CRUD : Delete - Example

nisit_id name surname

51051234 Steve Jobs

DELETE FROM studentsWHERE (nisit_id=51052345) OR (nisit_id=51052744);

Page 36: Introduction to database

CRUD : Delete - Practice

Delete the record you’ve modified earlier

Page 37: Introduction to database

Conclusion

Page 38: Introduction to database

Review

Getting to know Database Definition Organization

Practicing with Access 2007 Database operations

SQL Syntax CRUD Operations

Page 39: Introduction to database

Please do not hesitate to ask

Any Questions?