This action might not be possible to undo. Are you sure you want to continue?
What’s a Database?
• A Database is a collection of related items/facts/data arranged in a specific structure. • Some examples of databases include:
– – – – – – Dictionaries Phonebooks or Telephone Directories The Periodic Table of Elements TV Guide The Sears Christmas Wishbook Leonard Maltin's Movie Encyclopedia: Career Profiles of More Than 2,000 Actors and Filmmakers, Past and Present
Why Use Databases?
• Businesses use databases to keep track of their inventories, clientele, employees, sales, expenses, and to create and manage online stores, etc. • Libraries use databases to keep track of their books, periodicals, journal articles, and borrowed materials. • Universities use databases to keep track of student fees, registration, transcripts, course information, etc. • The Government uses databases to keep track of YOU (think census statistics).
Field Record Table
A basic fact or data element such as a name or number. A set of related fields. A group of related records.
Database A collection of one or more related tables.
Data Organization cont’d
Student ID First Name Last Name Email Address Program
Student ID Course Synonym Semester
Course Synonym Course Code Professor’s Name Credit Weight
that uniquely identifies each Record. student ID #’s. • Multiple Tables can be linked together by using a common field. . etc… Last Name Email Address • Each table usually contains a field. Program called the Primary Key.Data Organization cont’d Students • Recall that a record is a set of related fields. Student ID • Each record contains the same fields First Name but with different information. different students will have different names. – For example.
Data Organization cont’d • Primary Keys: Student ID. Course Synonym Students Student ID First Name Last Name Email Address Program Enrollment Student ID Course Synonym Semester Courses Course Synonym Course Code Professor’s Name Credit Weight Relationship Lines . Course Synonym • Common Fields: Student ID.
Cities • • But first… . Students 2. In this lab we’re going to create a simple database that contains two tables: 1.Microsoft Access • Microsoft Access is an application that allows us to create small databases.
Open Microsoft Access 2007 START PROGRAMS Microsoft Access 2007 Microsoft Access 2007 Double click on the ICON on desktop OR .
Getting Started • Select Blank Database • Create the database as “Test” .
simply click on the MS 2007 logo in the top left‐hand corner [ ] and the menu bar that you see on your right here will drop down giving you various options.Saving your Database • To save your document. including saving. .
it automatically saves with “.Saving your Database cont’d • When you save a database in MS Access 2007. . 2002 – 2003) by simply going to “Save As” and choosing to save the database in a different format from a previous version of MS Access.accdb” as its extension. you can also save your database so that it’s readable by earlier versions of MS Access (2000. • However.
• When a file is opened with Access. copy your database to a floppy disk or USB key. a bunch of stuff from the file is unpacked and is NOT put back until the file is closed. IF working from a floppy disk or a USB key. • Instead. • And as always. . DO NOT eject your disk or USB key until you close MS Access first. working off floppy disks & USB keys should be avoided all together. make backups of all your work.*** A Cautionary Note *** • There is an inherent danger with working off a floppy disk or a USB key with a MS Access database. work off the computer and when you’ve finished your work and closed down MS Access. • Meaning. • In fact.
Getting Help in MS Access 2007 • To get help in Access 2007. look for the help icon [ ] in the top right‐hand corner of the screen and click on it. . • You will be presented with a window that looks like the one here on the right.
Field Record . you will start off in the Datasheet View of a new table View Select a type of view for the table Data Type The kind of data that is stored in this field.Getting Started cont’d When you first create a new database.
– Click on the Office Button and select Save – Save the table as “Students” • Switch into the Design View: – Click on the View Button and select Design View .Saving Your Table Switching to Design View • To save our table.
636 characters) •Number: Numbers can have different sizes that can store larger or smaller numbers.768 to 32. For example: Integer: ‐32.767 (no decimals) Decimal: Includes 28 decimal points. Take a look at the bottom left of the window screen for the tab called “General”. let’s learn a little bit about the different types of data. Click on the “Field Size” option and scroll down to view the different number types that you can use. •Text: Short text (up to 255 characters) •Memo: Lengthy text (up to 65.Data Types Before we add fields to our table. .
• There are a few others that you can look at yourself. ..More Data Types • Date/Time: 9999 • Currency: • Yes/No: • AutoNumber: Date & time values for the years 100 to Currency values (includes 4 decimal places) A true or false value (i.e. a boolean value) A unique number (sequential or random) that MS Access assigns to every new record.
increment) – Name (text) – Age (number) – Enroll Date (date/time short date*) – City (text) Right-click on the “Student ID” field and select “Primary Key” * See the next slide for how to do this! .Adding Fields to the Table in Design View • Create the following fields: – Student ID (AutoNumber.
we had a Date / Time field as the 4th field in our table. We want the format of that enroll date to be a “short date”.Date / Time Fields • On the previous slide. • To do this… – Click on “Enroll Date” field – Now click on “Format” and… – Select “Short Date” from the list .
Student ID). • This means that for each new record MS Access will automatically create a unique number for the Primary Key (in this case. Student ID). we have since renamed it to “Student ID”).Primary Keys • A Primary Key is a value that uniquely identifies each record in a table (ex. • In the table that we just created the Primary Key is the first field in the table (Originally named “ID”. .
because we just made the table). It allows you to see the data that is currently in the table – (in this case none. – Notice how the AutoNumber field fills itself in. . • Create 5 different records for our table.Datasheet View • Save the table – Click on the Office Button – Select Save • Switch into the Datasheet view: – Click on the View Button – Select Datasheet View • This is the Datasheet view.
Datasheet View cont’d • Here is some sample data for the “Students" table: Make sure to save your table once you’ve finished entering all the data .
nd Creating a 2 • Create a new table – Go to the Create tab – Select Table – *Make sure you are in Design View Table • In Design View. add the following fields: – City (text) – Country (text) – Population (number Right-click on the “City” field and select “Primary Key” long integer) .
• Create 5 different records for the 2nd table and save. Make sure that the cities that appeared on our first table (Students) appear on this table as well. .nd Entering Data to the 2 Table • Save this table as “Cities” and enter the Datasheet view.
“Cities”. • This is a common field. that if we know a particular student’s hometown city (taken from the “Students” table). . we have a field called “City” that also appears in our 2nd table. then we should be able to access the corresponding information about that city located in the “Cities” Table (assuming there’s a record representing that particular city). then. • It stands to reason. in our 1st table. “Students”. • For example.Table Relationships • A relationship in a database is a logical link between two tables.
. go to the Datasheet tab (not datasheet view) and select Relationships • A list of all Tables and Queries pops up. – Double‐click on “Students” & on “Cities” – Click “Close” • This screen displays relationships between the tables ..Table Relationships cont’d • When viewing a table. • Click and hold onto the “City” field in the “Students” table and then drag it onto the “City” field in the “Cities” table. • A window will pop up on screen that looks like this. .
… & remember to SAVE! Relationship Line “City” is the Common Field. .Table Relationships cont’d Click on “Create” ….
• There are 6 kinds of queries: Select.Queries • What’s a Query? – Queries are questions – A Query selects a subset of data from one or more tables based on criteria that you give it. but doesn’t change anything. Insert. and Delete. Make‐Table. Update. • A Select query retrieves data from one or more tables. – For this class we will only cover Select queries. . • Now that we have two linked tables we can create some queries to retrieve data from the tables. Crosstab.
Query Example • Click on the Create tab and select Query Design • Add the “Students” and “Cities” tables .
Query Example cont’d • Now drag the fields that you want to include in your query to the bottom section of the screen. • For our example. add the “Student ID” field and the “Name” field from the “Students” table. .
. • Switch to Datasheet View • View the results of the query.Query Example cont’d • Save the query as “Query1”.
.Adding A Criteria to our Query • We will now add a criteria to the “Student ID” field. • Add a criteria (such as >2 for Student ID) • Save the query • Switch to Datasheet View • Note that only students who have a Student ID greater than 2 are displayed.
– For example.Query – User Input • Sometimes you want to be able to change the criteria of a query. we want to allow the user to only view information for a particular student that they specify – As well. we want to allow the user to specify any particular student by typing in his or her name • To do this we use Square Brackets: [ ] • Switch back to the Design View and… – Delete the “>2” criteria for Student ID field – Add “[Enter Name]” as the criteria for the Name field and SAVE .
. • This is because the query only returns the information for the particular student that the user specified.Query – User Input cont’d • Switch to Datasheet View • Enter the name of one of the students and click OK • Note that the text inside the square brackets [Enter Name] is the text that’s being displayed • Also note that only that particular student and his or her ID # is being shown.
.Queries – Linking Tables • Switch to Design View • Don’t forget to delete the criteria from the previous example • Add the “City” and “Population” fields from the “Cities” table to the query by dragging them down • SAVE and view the results by switching to the Datasheet View.
switch back to Design View Set the criteria for Student ID field to >2 and… Set the criteria for the Population field to >=100000 SAVE and switch to the Datasheet View .More than Criteria • • • • • You can have more than one specified criteria in a query! To illustrate.
• Notice the difference? OLD .More than Criteria cont’d NEW • Compare these results with query example we did where the only criteria was for student ID (>2).
as Criteria • • • • • Text can also be used as suitable criteria Switch back to Design View Delete the two criteria from the previous example and… Set the criteria for City field to Like “Toronto” SAVE and switch to the Datasheet View Note how only the information regarding Guelph is displayed .
.as Criteria cont’d • We can also use the wildcard character ‘*’ as part of the text • Switch back to Design View • Change the criteria for City field from: Like “Toronto” to: Like “To*” • SAVE and switch to the Datasheet View Note how the result is the same! This is because the wildcard character ‘*’ substitutes for any and all possible combinations.
1981 & May 25th. • For example.Logical Operators used in Criteria • When we talk about logical operators. 1983 by using the following criteria: >=8/3/1981 And <=5/25/1983 . we could list all birthdays between August 3rd. we’re referring to the operations of: ‘AND’ ‘OR’ • The ‘AND’ operator can be used to create a criteria that must satisfy 2 or more conditions.
we could list all the people named John and all people named Christina by using the following criteria: “John” Or “Christina” • Let’s do an example… .Logical Operators used in Criteria cont’d • The ‘OR’ operator can be used to create a criteria that must satisfy at least 1 of 2 (or more) conditions. • For example.
000 And <100.Logical Operators used in Criteria cont’d • Switch back to Design View • Delete the old criteria from the previous example and… • Set the criteria for Population field to >10.000 • SAVE and take a look at the results in Datasheet View. .
000 • SAVE and take a look at the results in Datasheet View.Logical Operators used in Criteria cont’d • Switch back to Design View • Slightly modify the criteria from the previous example by… • …setting the criteria for Population field to <10.000 Or >100. .
Query ‐ Sorting • Switch back to Design View • Delete the criteria from the previous example. Note that we can sort the query’s output in either ascending or descending order according to any of the fields. . • We are now going to sort the output of the query so that it displays in ascending order according to Name • SAVE and take a look at the results in Datasheet View.
• Note we want to make sure that even though “Name” is not being displayed. doesn’t mean that you have to display that field when the query performs its function. • For example. we still want the query to sort in ascending order according to the “Name” field.Query – Showing Relevant Fields • Just because a particular field is included in a query. . we’re going to modify our query so that the “Name” field is not being displayed in the Datasheet View.
Relevant Fields cont’d • Switch back to Design View • Remove the checkmark for “Show” under the “Name” field. • SAVE and take a look at the results in Datasheet View. .
it would have displayed every single city and its corresponding population for every single student.The Importance of Relationships • Recall The “Students” & “Cities” tables are linked through the common field: “City” • Without having specified this relationship between the two tables. . we would have gotten completely different results for our query. • For example. instead of showing the specific city and population for each of the different students.
Relationship Importance cont’d ☺ .
. having our information divided up into different. • This is extremely useful because it allows us to organize our data visually in a kind of Concept Map that can make our database easier to understand. but related. • As well.Relational Databases • This brings us to the idea of a relational database. lets us view the information in any number of different ways. • A relational database is a type of database that stores information in tables that are related to each other through common fields. tables.
Add the “Population” field. • For example. we’re going to use the AVG function to determine the average population of the 5 cities in the “Cities” table. save the query as “Average Population” . • • • • Create a new query in Design View. Add the “Cities” table.Introduction to Functions • Functions can be used in queries. Now.
Introduction to Functions cont’d • Click on the Totals button – This can be found on the Design tab • This will cause a new row called “Total” to show up in the query design area. • Click and scroll down to find the “Avg” function. • SAVE & switch into the Datasheet View .
get it? query?) to the online conferences.That’s all for this tutorial! • As usual. if you have questions come to one of the Zoe’s or one of the TA’s office hours or post your ‘query’ (hehe. • Next Access Tutorial: – Functions and Forms and Reports (oh my!) .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.