ENGG1811: Databases 1

Similar documents
Full file at

PowerPoint Presentation to Accompany GO! All In One. Chapter 13

9. Introduction to MS Access

HKTA TANG HIN MEMORIAL SECONDARY SCHOOL SECONDARY 3 COMPUTER LITERACY. Name: ( ) Class: Date: Databases and Microsoft Access

COMM 391. Objectives. Introduction to Microsoft Access. What is in an Access database file? Introduction to Microsoft Access 2010

CHAPTER 6 SUMMARY. Objective 1: Identify Good Database Design

Index. B backing up 76 7

Microsoft Access XP Queries. Student Manual

Level 6 Relational Database Unit 3 Relational Database Development Environment National Council for Vocational Awards C30147 RELATIONAL DATABASE

Introduction to Computer Applications. CISY 1225 Chapter 10. Zahoor Khan, PhD

Access - Introduction to Queries

Microsoft Office Access 2013: Part 01. Lesson 01 - Getting Started with Access

Introduction to Microsoft Access 2016

Access Intermediate

Exploring Microsoft Office Access Chapter 2: Relational Databases and Multi-Table Queries

Microsoft Access Illustrated. Unit B: Building and Using Queries

Microsoft Access 2016

Microsoft Access 2016

MIS Cases: Decision Making With Application Software, Second Edition. Database Glossary

Getting started with Ms Access Getting Started. Primary Key Composite Key Foreign Key

Access Intermediate

Access Intermediate

Tutorial 3 Maintaining and Querying a Database. Finding Data in a Table. Updating a Database

Microsoft Access XP (2002) Queries

MS-Access : Objective Questions (MCQs) Set 1

INTRODUCING. Access. R. Kumar

Data Information Database Database System Data 1. Known facts that can be recorded and have an implicit meaning.

IT2.weebly.com Applied ICT 9713

STIDistrict Query (Basic)

Objective 1: Familiarize yourself with basic database terms and definitions. Objective 2: Familiarize yourself with the Access environment.

Microsoft Access XP (2002) - Advanced Queries

Schnieder_index.qxd 7/27/05 1:08 PM Page 481 INDEX. Symbols

Follow these steps to get started: o Launch MS Access from your start menu. The MS Access startup panel is displayed:

Massachusetts Institute of Technology Department of Urban Studies and Planning

Data about data is database Select correct option: True False Partially True None of the Above

Microsoft Office Illustrated Introductory, Building and Using Queries

As your databases continue to evolve, you will need to incorporate advanced queries and reports. This chapter addresses how to create and use action

Advanced Topics in Access: Queries

MIS 2502 Access 2007 Tutorial

Module 5. Databases. Astro Computer Training. Page 1

K Hinds Page 1. Information Communication Technology Microsoft Access

Microsoft Certified Application Specialist Exam Objectives Map

SECTION 1 DBMS LAB 1.0 INTRODUCTION 1.1 OBJECTIVES 1.2 INTRODUCTION TO MS-ACCESS. Structure Page No.

Microsoft Access 2010

Bangladesh Open University

Exploring Microsoft Office Access 2007

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Sloan School of Management

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

AUSTIN COMMUNITY COLLEGE CONTINUING EDUCATION. INTERMEDIATE DATABASE/FILE AMANGEMENT (Access Intermediate) (12 hours) ITSW 1055 COURSE SYLLABUS

Microsoft MOS- Using Microsoft Office Access Download Full Version :

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

MODULE 5 DATABASES. Content

Microsoft Access 2013

Microsoft Access 2013

Access ComprehGnsiwG. Shelley Gaskin, Carolyn McLellan, and. Nancy Graviett. with Microsoft

Word Module 5: Creating and Formatting Tables

Computer Skills MS Access Work Sheet # 1

DATA Data and information are used in our daily life. Each type of data has its own importance that contribute toward useful information.

Access Objects. Tables Queries Forms Reports Relationships

SEE GRADING CRITERIA AT THE BOTTOM. Database Tables Lookup Wizard Relationships Forms Queries Reports

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Access 2000 MICROSOFT. Level One Basic. Version N2

Access 2007: Advanced Instructor s Edition

M I C R O S O F T A C C E S S : P A R T 2 G E T T I N G I N F O R M A T I O N O U T O F Y O U R D A T A

The specific steps to build Wooden Crafts database are here: 1. Create New Database. i. After opening Access, click Blank Desktop Database :

Complete Quick Reference Summary

Rapid Application Development

ICT IGCSE Databases (Access)

Create and Modify Queries 7

VETtrak Data Insights User Guide. for VETtrak version

FOCUS ON: DATABASE MANAGEMENT

Microsoft Access 2007 Module 2

Microsoft Access 2007 Module 1

Microsoft Office 2010: Introductory Q&As Access Chapter 2

Database Concepts Using Microsoft Access

ACCESS 2007 FOUNDATION

IFF 1414 Intro to Database. Notes

Access 2016 Foundation. North American Edition SAMPLE

Access Module 2: Building and Using Queries

TECHNOLOGY COMPETENCY ASSESSMENT MODULE Microsoft Access

Using Microsoft Access

Bridge Program Computer Skills Self-Inventory

Advanced Queries: Moving Beyond the Select Query Instructor: Edwin V. Bonilla

ACCESS 2007 ADVANCED

Copyright 2009 Labyrinth Learning Not for Sale or Classroom Use LESSON 1. Designing a Relational Database

ICT IGCSE Databases (Access) A database is a collection of data or information stored in a logical format.

IGCSE Information Communication Technology (ICT) Syllabus code Section 5: Data types

Hours Assignments:

By: Access 2007 Table

Microsoft Office Access 2013: Part 01. Lesson 04 - Creating Advanced Queries

Nutzen Sie die Dettmer-Seminarunterlagen für Access bei einmaligem Kauf über Jahre hinaus für Ihre eigenen Schulungen

Using Microsoft Access

Access 2016 Foundation SAMPLE

Database Design Practice Test JPSFBLA

Microsoft Access Description

Access 2010 Foundation. Access 2010 Foundation SAMPLE

Learn Well Technocraft

Relational Databases. Week 13 LBSC 671 Creating Information Infrastructures

Microsoft Office Specialist Access 2016

Simple Invoicing Desktop Database with MS Access 2013/2016. David W. Gerbing School of Business Administration Portland State University

Transcription:

ENGG1811 Databases Computing for Engineers Why Databases How do they work? Views of databases, and Linking multiple databases Problems that databases try to deal with Table, field, record, keys, etc Different types of Queries SQL Multiple tables Relationships between tables, Referential Integrity Etc, etc. Why Use Databases? Manual record keeping can be a time-consuming and tedious job! Imagine you re a manager of a bookshop before the invention of computers. You have to keep paper records for every book (the title, author, price, publisher, etc) every publisher (name, address, phone, discount policy, etc) every order (date placed, books, copies, etc) And say you keep them in separate folders. Now you also need to keep them up to date Meaning lots of visits to your filing cabinet! ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 1 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 2 Why Use Databases? Today a task like that would be done using a database, a type of record-keeping application which offers many advantages: makes it easy to enter, retrieve and update records makes reports about part or whole of records easy removes redundancy from records maintains consistency and integrity across records security controls access to part or all of the records permits concurrent data sharing by many users First, let s have an overview of how do they work?.. later we will discuss some of these topics in detail.. Databases are today an indispensable tool for efficiently keeping track of complex information. They let you rapidly search your records for one specific piece of information, or produce lists of things sorted in different ways. They help catalogue, sort, count and label your stock. They help place and receive orders, do audits, and find and keep clients ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 3 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 4 How Do They Work? Records (one per line) Field Names ISBN Number Title Author Year List Price Publisher 0-13-503393-4 Exploring PowerPoint Grauer/Barber 1996 $28.95 Prentice Hall 0-13-503362-2 Exploring Access Patel/Rao 1995 $35.50 Prentice Hall 0-13-504016-9 Exploring Excel Flanagan 1997 $18.00 Addison Wesley 0-13-503982-2 Exploring Word Cornell/Arnol 1996 $42.25 Prentice Hall 0-13-502344-1 Introduction to Shepherd 1997 $58.00 Addison Wesley Win95 Query Records can be searched based on their field values. For example, the following lists all records where Publisher = Prentice Hall, and Year > = 1996 ISBN Number Title Author Year List Price Publisher 0-13-503393-4 Exploring PowerPoint Grauer/Barber 1996 $28.95 Prentice Hall 0-13-503982-2 Exploring Word Cornell/Arnol 1996 $42.25 Prentice Hall Data is stored in the form of tables Each column represents a field. A field can store a specific type of data, i.e. number or character string or dollar value Each row represents a record. We can add, remove and alter records. Some times, records are also known as tuples. The field (or combination of fields) that is unique for each record is also known as primary key Records can be modified based on a search criteria. For example, the following adds $10 to all the books published in 1997 ISBN Number Title Author Year List Price Publisher 0-13-503393-4 Exploring PowerPoint Grauer/Barber 1996 $28.95 Prentice Hall 0-13-503362-2 Exploring Access Patel/Rao 1995 $35.50 Prentice Hall 0-13-504016-9 Exploring Excel Flanagan 1997 $28.00 Addison Wesley 0-13-503982-2 Exploring Word Cornell/Arnol 1996 $42.25 Prentice Hall 0-13-502344-1 Introduction to Shepherd 1997 $68.00 Addison Wesley Win95 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 5 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 6 ENGG1811: Databases 1

Reports The result of a search can also be used to generate reports. Reports are customised printouts listing or summarising part or all of the database for a specific purpose. Forms for Databases Forms can be used to display, enter and modify records. They can hide database details and provide better user interface and avoid invalid inputs Report generation is made easy by the use of database tools ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 7 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 8 Views of the Database ISBN Number Title Author Year List Price Publisher Linking More Than One Database 0-13-503393-4 Exploring PowerPoint Grauer/Barber 1996 $28.95 Prentice Hall 0-13-503362-2 Exploring Access Patel/Rao 1995 $35.50 Prentice Hall 0-13-504016-9 Exploring Excel Flanagan 1997 $18.00 Addison Wesley 0-13-503982-2 Exploring Word Cornell/Arnol 1996 $42.25 Prentice Hall 0-13-502344-1 Introduction to Shepherd 1997 $58.00 Addison Wesley Win95 ISBN Number Title Author Year List Price Pub ID 0-13-503393-4 Exploring PowerPoint Grauer/Barber 1996 $28.95 P3 0-13-503362-2 Exploring Access Patel/Rao 1995 $35.50 P3 0-13-504016-9 Exploring Excel Flanagan 1997 $18.00 P1 0-13-503982-2 Exploring Word Cornell/Arnol 1996 $42.25 P3 0-13-502344-1 Introduction to Shepherd 1997 $58.00 P1 Win95 Pub ID Pub name Phone Address P1 Prentice Hall (02) 933377 34 George... P2 Sams Publishing (02) 912345 23 Elisabeth... P3 Addison Wesley (02) 967733 11 Walker... Title Author ISBN Number List Price Exploring PowerPoint Grauer/Barber Exploring Access Patel/Rao Exploring Excel Flanagan Exploring Word Cornell/Arnol Introduction to Win95 Shepherd 0-13-503393-4 $28.95 0-13-503362-2 $35.50 0-13-504016-9 $18.00 0-13-503982-2 $42.25 0-13-502344-1 $58.00 ISBN Number Title Author Year List Price Pub ID Pub name Phone Address 0-13-503393-4 Exploring PowerPoint Grauer/Barber 1996 $28.95 P3 Addison Wesley (02) 967733 11 Walker... 0-13-503362-2 Exploring Access Patel/Rao 1995 $35.50 P3 Addison Wesley (02) 967733 11 Walker... 0-13-504016-9 Exploring Excel Flanagan 1997 $18.00 P1 Prentice Hall (02) 933377 34 George... 0-13-503982-2 Exploring Word Cornell/Arnol 1996 $42.25 P3 Addison Wesley (02) 967733 11 Walker... 0-13-502344-1 Introduction to Shepherd 1997 $58.00 P1 Prentice Hall (02) 933377 34 George... Win95 Author View Price View A view of the database displays some of the fields A view can hide unnecessary fields and data for a given task ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 9 Different tables can be joined together based on some common field values. Such tables could be on the same computer or any where on a network User can search the new joined database just like any other database ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 10 Some Applications of Databases Personal Use - keeping track of your CDs, phone numbers Charities - donations, benefactors and recipients addresses Small and Large Businesses - stock control, payroll, tax law compliance, employees, product or service information, etc. Libraries - catalogs, orders, lendings Scientific Organisations - maintenance of scientific data, control of equipment, chemicals or other supplies Educational Institutions - allocation and scheduling of resource materials, records of student marks Law Enforcement - criminal records, forensic data, fraud detection Governments - census data, births and deaths, economic data, citizenship records, taxation records, fraud detection... Abuses of Databases When an attempt to introduce the Australia Card - an identification document giving a unique number to each citizen - was made in 1987, protesters in every state accused the government of being Big Brother People didn t want any government to establish a central computer keeping all the facts about individuals in one place. This would give it too much power over people - power that was bound to be abused The Australia Card idea was abandoned as undemocratic But the government didn t need to put all the data into one database to have such a powerful tool of control. All it needed was the single identifying number to appear on many, much smaller and more acceptable databases held by the tax office, welfare organisations and law enforcement agencies. It could link these together at any time to make a complete dossier on one person or a list of persons This is probably why you always need to quote your Tax File Number - even for things that have nothing to do with taxation ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 11 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 12 ENGG1811: Databases 2

Data vs. Information Let s now discuss some of these Database topics in more detail Data raw material: facts and figures Cell entries in database tables Information organised data records, tables, databases, reports information is used to inform ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 13 Information Technologists (and others) argue about the meaning of the terms data, information and knowledge Google these terms to see how much is written about them ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 14 When to use a Database Databases are ideal for maintaining data related to objects (e.g., student records, inventories, etc.) This data can be queried, sorted, etc. and the relationship between the objects and their attributes is maintained. While they can be used to perform numeric calculations, they are not usually optimised for this task. Databases One important feature of a database is that the stored information is organised and structured in a particular way Usually databases try to allow for fast retrieval of information (via queries) even when they contain vast amounts of data It is important to pay careful attention to the design so as to structure the storage of data appropriately ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 15 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 16 Database Management System Structured Data Database Management System (DBMS) is a computer program that stores related information in a structured way so as to maintain relationships between information and allow access to and modification of data Most common model is Relational DBMS Structure of information in DBMS is maintained by a relation(s) A relation associates the data belonging to a single object or entity For example: Students: Name, address, ID number, courses enrolled, etc. Stock: Part #, description, quantity, unit price We shall see later that relations are stored in tables ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 17 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 18 ENGG1811: Databases 3

Example Databases Example Databases Catalogues (e.g., library, museums) Student records Inventories (e.g., parts, stock) Address books Events (e.g., swim meeting) Inventory Part No. Description Quantity Unit Price P001 Widget 10 $1.50 P002 Gadget 12 $10.20 P201 Object 25 $0.12 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 19 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 20 Student database Example Databases ID Name Faculty Degree Credit Points 1234567 Jane Doe Science MSc 50 7654321 John Smith Arts BA 48 Differences Between Spreadsheets and Databases In a spreadsheet, changes to elements may affect other elements however the elements are not related in any other way. A database groups the attributes of an object together and treats them as belonging to that object. In a database, elements have a type (e.g., text, number, date, yes/no, etc.) ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 21 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 22 When Should You Use a Database Rather than a Spreadsheet? Problems that Databases Try to Deal With Database stores information in a structured way as relations: attribute values of a single object Different attributes have a data type Spreadsheet doesn t maintain information in this way (only formula dependencies) and has only a few data types Use DBMS when it is important to maintain attributes of objects as single entities, and relationships between objects Spreadsheet is normally useful for calculations and visualisation of information Redundancy and inconsistency of data Different copies of information may exist (redundancy) and some attributes may differ (inconsistency) Access May need to allow/restrict access to different portions of data Multiple users accessing/modifying data at the same time Integrity Constraints on data that can be stored (e.g., only Gold status members entitled to a discount) ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 23 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 24 ENGG1811: Databases 4

MS Access Database Tables MS Access is a Relational DBMS It allows you to: Maintain tables Query the database Produce forms for data entry and viewing information Produce reports for viewing information Collection of objects or entities In database terminology, collection of records Each record has a number of attributes or fields describing entity An MS Access database may have a number of tables ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 25 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 26 Records Fields Information about a single object Example: P002 Gadget 12 $10.20 A row of database table Each attribute is known as a field of the record or table Attribute of an object or entity Examples: part number, quantity, name, student number, location A column of database table Every field has a data type (e.g., numeric, text, hyperlink, etc.) Information that does not conform to the data type cannot be entered into the database One way for DBMS to maintain integrity of data ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 27 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 28 Field Data Types Why Enforce Data Types? Autonumber - MS Access adds value Numeric Yes/No - Boolean: true/false; on/off values Text Memo Date/time Currency OLE object - pictures, etc. Hyperlink - URL Prevent data entry errors Reduce amount of storage space required to store database ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 29 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 30 ENGG1811: Databases 5

Creating Tables Creating Tables Design view Name fields and assign data type Wizard Select from some standard field names Enter data Enter data directly into tables Can modify in Design View later ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 31 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 32 Design View Enter Data ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 33 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 34 Datasheet View Design View ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 35 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 36 ENGG1811: Databases 6

Key Fields One or more fields of a database table Uniquely distinguish each record in a database table No two rows of the database can have the same value for the key field(s) When key consists of more than one field it is referred to as a compound key Examples: student number, part number, ISBN, Dewey decimal number If key field is not a common attribute of an object, may need to create one (e.g., part number) Operations on Databases Queries Select records from table(s) satisfying certain criteria MS Access allows a number of different types of queries Sorting and Filtering table data Construct forms for data entry and display Develop reports to present data ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 37 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 38 Queries Once you have a large amount of data stored in a database, you need a quick and easy way to access that information Queries allow you to access data that conforms to certain criteria Queries also allow you to update and modify data in tables Let s initially consider queries on single database tables Queries When a query is performed, it locates the records in an MS Access table satisfying the stated criteria The records selected in this way are stored in a dynaset - a dynamic subset of a table The dynaset exists temporarily to show the results of the query Changes made to the dynaset will be reflected in the orginal table ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 39 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 40 Types of Queries Creating Queries There are 4 different types of queries in MS Access Select query Most basic form of query, returning records that satisfy specified criteria Action query Update query Append query Delete query Make-table query Total query - performs calculation Crosstab query MS Access provides a number of ways of designing queries Query wizard Design View SQL - Structured Query Language ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 41 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 42 ENGG1811: Databases 7

Query Wizard As with most wizards, the Query Wizard guides you through the design of a basic query Can set: Tables used Fields Can refine design in Design View Design View A more flexible way of designing queries is in Design View The following steps will guide you in designing a basic Select Query Select tables containing fields that you would like to view or use in specifying criteria Select fields in the order you wish to view them Set any sort criteria Select/De-select fields that will be displayed by the query Set criteria ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 43 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 44 Datasheet View For tables, Datasheet view can be used to add, edit and delete records in the tables Changes made to the table in Datasheet view cannot be reversed For queries, Datasheet view can be used to view the results of performing a query Datasheet displays the dynaset Again, changes made in Datsheet view will be reflected in the original table Running a Query Once designed a query can be performed by: Clicking on the Run icon (!) in the menu bar or from the Query menu Selecting Datasheet view Results of query will be displayed in Datasheet just as you would view the contents of a database table Results of query are temporarily stored in a dynaset ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 45 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 46 Select Query The simplest Select Query simply lists certain chosen fields from among those in the table No criteria are specified so all records are displayed but only the selected fields are shown for each record The steps involved: Select tables Select fields to display Impose any sorting order Tables Involved in query Sort order Select Query Criteria rows Fields to display ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 47 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 48 ENGG1811: Databases 8

Sorting Query Results Results of a query can be sorted on certain fields by specifying a sort order Ascending or Descending Sort order is applied on fields from left-to-right I.e., Results are sorted on left-most field with a sort order specified first, then next field to the right with a sort order specified and so on How can we sort in a different order? Specifying Selection Criteria Can reduce the number of records displayed by specifying criteria Each record whose fields match the specified criteria will be displayed (but note that only the selected fields are shown) Several criteria rows can be specified In any given criteria row, a record must match every field with a criterion If there are multiple criteria rows, the record must match at least one row to be displayed ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 49 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 50 Numeric Criteria Numeric Criteria For numeric fields: Entering a single number in the criteria row of a field means that only records containing that value in the field will match Can prefix number with logical criteria <, <=, >, >=, <> ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 51 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 52 Text Criteria Text Criteria Can specify text in double quotes: search text Double quotes only necessary if search text contains space Again, only records that have the text in that field will match Text is not case sensitive Can use wildcards for matching more sophisticated patterns ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 53 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 54 ENGG1811: Databases 9

Wildcards Wildcards can be used to specify patterns in a text query criterion * - matches 0 or more characters? - matches any single character [] - match any single character specified inside the brackets [!] - match any single character except those specified inside the brackets [] - match a range of characters (e.g., a - z) # - matches any single numeric character To search for literal wildcard characters place them in brackets (e.g., [?] matches the character? ) AND vs. OR In a given criteria row all fields must match criteria (AND) If multiple criteria are specified, record can match any of them (OR) Can also use logical operators to specify criteria in a single field E.g., >=110 And <=130 Value between 110 and 130 E.g., A* Or B* Strings starting with an A or B ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 55 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 56 BETWEEN, IN, LIKE Between - specifying ranges Between 110 And 130 Same as >=110 And <= 130 In - lists of values In( two, four ) Same as two Or four Like - searching patterns Like *z Strings that end in letter z Dates and Times Can specify dates and times by surrounding them with # signs E.g., #26/4/05#, #April 26, 2005#, #26-Apr-2005#, #1:15PM#, #13:15PM# MS Access also provides the following functions Day, Month, Year, Weekday, Hour, DatePart, Date Null Criterion to select fields where no value has been entered Use key word Null in Criteria row Take care not to quote the string Null otherwise you will be looking for the text string composed of those four letters ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 57 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 58 Parameter Query The queries that we have designed so far are static. They do not request input from the user. Can do so by using the criterion: Like [Prompt text] Action Queries Action queries allow you to modify and update values in database table Update query Append query Delete query Make-table query The effects of action queries cannot be undone ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 59 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 60 ENGG1811: Databases 10

Update Query Update Query can modify the values in database records Specify an expression in the Update To: row that determines the new value of a field NOTE: Once modified, a field cannot be changed back to its previous values Append Query Append Query will add records from one to table to the end of another table Must specify table to which records will be added Need to specify which fields of source table will be added to target table and also to which fields they will be added (in case the field names differ) ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 61 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 62 Delete Query Make-table Query Delete Query removes records from a table Can use to remove outdated data or data that is no longer required NOTE: Cannot undo the deletion of records When you perform a Select Query, Total Query, etc., results are temporarily stored in a dynaset They are not stored in a table in the MS Access database A Make-table Query will store the results of a query in a new table in the database ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 63 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 64 Total Query Total Query Total Query performs calculations on groups of records Click on the sigma icon Σ in Design View to create a Total Query Total: row appears Can use this to group records according to the same values using Group By Can apply functions to perform calculations Sum, Avg, Min, Max, Count, StDev, Var, First, Last, Expression, Where ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 65 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 66 ENGG1811: Databases 11

Crosstab Query Crosstab Query A Crosstab Query allows you to summarise data in row and column format Must specify one field whose values will be the columns and can have several fields whose values will form rows Can apply a function to the values of a third field Sum, Avg, Min, Max, Count, StDev, Var, First, Last, Expression, Where ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 67 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 68 SQL Structured Query Language Standardised language for querying and manipulating databases Used in virtually all commercial DBMSs Can view SQL for a query that you have designed by selecting SQL View from View menu SQL s query structure has the following syntax SELECT List of fields FROM Table(s) WHERE Constraints on the rows Example: SQL SELECT Enrolments.StuID, Student.FirstName, Student.LastName, Courses.CourseName, Enrolments.Grade FROM Student INNER JOIN (Courses INNER JOIN Enrolments ON Courses.CourseID = Enrolments.CourseID) ON Student.StuID = Enrolments.StuID WHERE ((Enrolments.Grade)="FL") AND ((Enrolments.CourseID)="MATH1090"); ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 69 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 70 Multiple Tables What is wrong with the following table? Data redundancy and multiple tables; Linking tables Order ID Description Quantity Unit Price Family Name Given Name Address O001 Widget 5 $1.50 Doe Jane 412 Anzac Pde, KINGSFORD 2032 O002 Widget 12 $1.50 Smith John 3 Main St, YOUNG 2594 O003 Gadget 7 $2.05 Doe Jane 412 Anzac Pde, KINGSFORD 2032 O004 Widget 14 $1.50 Doe Jane 412 Anzac Pde, KINGSFORD 2032 O005 Gadget 4 $2.05 Smith John 3 Main St, YOUNG 2594 O006 Gadget 23 $2.05 Smith John 3 Main St, YOUNG 2594 O007 Widget 3 $1.50 Doe Jane 412 Anzac Pde, KINGSFORD 2032 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 71 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 72 ENGG1811: Databases 12

Multiple Tables Multiple Tables Parts Part ID Description Unit Price P01 Widget $1.50 Customers Customer ID Family Name Given Name Address C01A Doe Jane 412 Anzac Pde, KINGSFORD 2032 C02A Smith John 3 Main St, YOUNG 2594 P02 Gadget $2.05 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 73 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 74 Multiple Tables Orders Order ID Customer ID Part ID Quantity O001 C01A P01 5 O002 C02A P01 12 O003 C01A P02 7 O004 C01A P01 14 O005 C02A P02 4 O006 C02A P02 23 O007 C01A P01 3 Multiple Tables Customers Orders Parts Customer ID Last Name First Name Address Order ID Part ID Customer ID Quantity Part ID Description Unit Price ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 75 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 76 Multiple tables The previous example illustrates some of the advantages of multiple tables. In a single table with multiple relationships, Data is duplicated many times Storage space is wasted Likelihood of introducing errors increases In designing a database we need to identify the tables required and create relationships between them to show how the data they contain is related Relationships exist between a field in one table (usually a primary key) and a field in another table Normalisation The problems on the previous slide can be reduced through the process of normalisation Normalisation is a complex process and we will not go into the theory here. The essence of the process can be described through several simple rules. ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 77 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 78 ENGG1811: Databases 13

Normalisation Primary Keys and Foreign Keys Every field should be atomic and represent unique type of data Every table must have a primary key consisting of one or more fields. The primary key must be unique for each record. (Use natural keys where possible.) For every value of the primary key, field values must be relevant and completely describe objects. Changes to data in a field other than the primary key should not affect data in other fields. Data generally shown in de-normalised (flattened) form in reports Notice that Customer ID field occurs in both Customers table and Orders table. In Customers table it uniquely identifies each record Customer ID is the primary key of the Customers table In the Orders table Customer ID field does not uniquely identify each record but serves to link to the Customers table Customer ID is a foreign key in the Orders table ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 79 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 80 Relationships Each customer can have many orders but an order can only have one customer This is an example of a one-to-many relationship One customer can have many orders There are situations in which you might have one-toone relationships For every record in the first table there is exactly one related record in the second and vice versa This can help to separate data that is not as important or that needs to be restricted If relationship is many-to-many you will need to introduce another database table Creating Relationships Once the tables have been created you can create relationships between them Note that fields in different tables do not have to have the same field name in order to be related. They must however have values in common To create relationships, select Relationships from menu or Tools Relationships In dialog box that appears select tables; drag a field name in one table to the field you want to link it to in the other table These relationships are created for the table as a whole. Can also create them for queries only ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 81 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 82 Referential Integrity Tables in database must have consistent values Example 1: Creating an order for a non-existent part (obvious) Example 2: Deleting a part when an order for that part still exists (not always obvious) This is known as referential integrity MS Access will check referential integrity if you check the appropriate item when creating a relationship between tables Queries on Multiple Tables Queries on multiple tables are similar to those for single tables In Query Design View first add all the required tables Those containing fields which will be displayed or have criteria specified May also need to add any tables that link these tables together Select fields that need to be displayed or have criteria specified as you would with a single table Where a field occurs in two tables (usually because it links them together) you can select this field from either table ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 83 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 84 ENGG1811: Databases 14

Joins In query using multiple tables, so far records from table are only included where the fields that link them have the same value (e.g., record in Orders table with same Customer ID as record in Customers table) This is known as an equi-join There are other ways of joining tables For example, you may want to see all Customers that have not placed an order Can use outer join to display all records in one table with matching records in another if they exist Can do this by clicking on link between tables in Query Design View or using Relationships dialog Security A weak form of security is provided by Data Types, Validation rules, Locking fields, etc. This helps to ensure that incorrect data is not entered. Stronger forms of security are available Can set database password Can also set user and group level access ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 85 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 86 Validation Rules Some fields require that data is of a particular form that cannot be checked entirely by conforming to the field data type For example, Customer ID in Customers table has been restricted to letter C followed by two digits followed by a character Validation Rule can be set in Table Design View for this field to restrict the data that can be entered into this field. Can also be set in Forms using field properties. Locking Fields Fields in Forms can be locked to stop the field from being altered Set Locked property of field in Form to Yes This is a very weak form of security as it can be easily circumvented For example: Like C##? (see Wildcard characters for more) Validation Text is text that will appear if incorrect data is entered into field ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 87 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 88 Filters and Sorting In similar fashion to MS Excel, can filter and sort records when in Datasheet View (Table and Queries) Two methods for filtering Filter by Selection Filter by Form Forms and Reports.Demonstration if time permits.. Can sort fields by Sort Ascending and Sort Descending ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 89 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 90 ENGG1811: Databases 15

Summary DBMS When we have large amounts of data to store and manipulate can use DBMS A DBMS stores data in a structured way One of the most common database models is the Relational DBMS Spreadsheet does not maintain relationship between an entity s attributes in the way a database does DBMS tries to deal with redundancy, consistency, integrity of and access to data Summary Database structures Database consists of tables storing information about objects and entities Each table consists of a number of records (rows) Each record has a number of fields storing the values of attributes for an object (columns) Each field has a data type to which the value must conform A key field(s) uniquely identifies each record ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 91 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 92 Summary Queries Queries can be used to access, modify and update data stored in database tables Records satisfying query criteria are displayed in dynaset - a dynamic subset of a table Select query displays those records satisfying criteria Crosstab query displays results of query in row/column format Parameter query obtains input from user in order to perform query Action queries modify and update records: Update, Append, Delete and Make-table queries Total query performs calculation Summary MS Access Multiple views provided for flexible management of data Design view can be used to create queries while Datasheet view displays results Criteria can be specified to select records of interest, including Boolean and wildcard operators SQL - standardised language for querying and manipulating databases Importing and exporting data MS Access allows for various levels of security in a database Filters and sorting can also be applied to database in similar way to MS Excel ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 93 ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 94 Summary Relationships Multiple tables reduce data redundancy in database The process of normalisation can help structure database into multiple tables Once multiple tables are constructed need to link them using relationships Queries using multiple tables require that tables be linked Relationships can be one-to-many and one-to-one Referential integrity can be checked by MS Access ENGG1811 UNSW, CRICOS Provider No: 00098G Databases slide 95 ENGG1811: Databases 16