This document provides an introduction and overview of databases and the basic operations used to manage data in a database using Microsoft Access 2007. It defines what a database is, how data is organized in tables with rows and columns, and when it is appropriate to use a database. It also outlines and provides examples of the basic CRUD (create, read, update, delete) operations used in structured query language (SQL) to manipulate data, including inserting, selecting, updating, and deleting records from database tables.
4. 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 :-(
5. Consists of a table, multiple fields and many columns A Really Simple Database
6. Organization of Database Tables Fields (Columns) Has many types Primary Key (Optional) Records (Rows, Entries)
7. When to Use Database? (1/3) Appropriate Appropriate Inappropriate Appropriate Inappropriate Appropriate
8. When to Use Database? (2/3) Transaction records Logging Blog/Forum Media Library Shopping list Music playlist Appropriate Inappropriate
9. When to Use Database? (3/3) Managing mass amount of information Sharing Information between many users Manipulating complicatedly related information Need security Desire organization
10. Under the Hood Infrastructure of Database Implementations in which we are going to learn
16. 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
17. CRUD Create new tables and records Retrieve records from tables Update tables’ definition and record’s data Delete existing tables and records
18. CRUD : Create INSERT INTO <table_name> (<field_list>) VALUES (<value_list>); AutoNumber field must not be included Examples INSERT INTO students (nisit_id, name, surname) VALUES (51052744, “Pongsakorn”, “U-chupala”);
19. CRUD : Create - Example INSERT INTO students(nisit_id, name, surname) VALUES (51052744, “Pongsakorn”, “U-chupala”);
20. CRUD : Create - Example INSERT INTO students(nisit_id, name, surname) VALUES (51052744, “Pongsakorn”, “U-chupala”);
21. CRUD : Create - Practice Insert a record with every field specified
22. CRUD : Retrieve SELECT <select_list> FROM <table_name> [ WHERE <search_condition> ] [ ORDER BY <order_expression> [ ASC | DESC ] ]; Select which fields to retrieve Examples SELECT field_1, field_2 FROM table_name … SELECT * FROM table_name …
23. CRUD : Retrieve SELECT <select_list> FROM <table_name> [ WHERE <search_condition> ] [ ORDER BY <order_expression> [ ASC | DESC ] ]; Available operators: =, <, >, <=, >=, <> Modifiers: AND, OR, NOT, () Examples … WHERE student_id=1 … … WHEHE (<cond1>) AND (<cond2>) …
24. CRUD : Retrieve SELECT <select_list> FROM <table_name> [ WHERE <search_condition> ] [ ORDER BY <order_expression> [ ASC | DESC ] ]; 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 …
25. CRUD : Retrieve - Example SELECT name, height FROM students WHERE height>160 ORDER BY height DESC;
26. CRUD : Retrieve - Example SELECT name, height FROM students WHERE height>160 ORDER BY height DESC;
27. 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
28. CRUD : Update UPDATE <table_name> SET <field_value_list> [ WHERE <search_condition> ]; 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;
29. CRUD : Update - Example UPDATE students SET name=“Knight”, surname=“Baron” WHERE nisit_id=51052744;
30. CRUD : Update - Example UPDATE students SET name=“Knight”, surname=“Baron” WHERE nisit_id=51052744;
31. CRUD : Update - Practice Update the record that you’ve added earlier with different data
32. CRUD : Delete DELETE FROM <table_name> WHERE <search_condition> ; Delete every record that match the search condition Examples DELETE FROM students WHERE id=1 DELETE FROM students WHERE (name=“Knight”) AND (surname=“Baron”);
33. CRUD : Delete - Example DELETE FROM students WHERE (nisit_id=51052345) OR (nisit_id=51052744);
34. CRUD : Delete - Example DELETE FROM students WHERE (nisit_id=51052345) OR (nisit_id=51052744);
35. CRUD : Delete - Example DELETE FROM students WHERE (nisit_id=51052345) OR (nisit_id=51052744);
36. CRUD : Delete - Practice Delete the record you’ve modified earlier