ms access concepts

10
DatabaseConcepts TableofContents WhatisaDatabase? ............................................................................................................................ 1 CommonlyUsedTerms ...................................................................................................................... 1 TypesofDatabases .............................................................................................................................. 2 WhatArethePartsofaDatabaseProgram? ....................................................................................... 2 IdentifyingtheFieldstoInclude ......................................................................................................... 3 DatabaseStructure ............................................................................................................................... 4 FieldLengths ....................................................................................................................................... 6 DataStorage ........................................................................................................................................ 6 Relationality:MakingDatabasesWorkIntelligently .......................................................................... 7 DataEntryandDisplay:Forms ........................................................................................................... 7 OrganizationofData(SortFunctions) ................................................................................................ 8 QueriesandSearchConditions(ReportFunctions) ............................................................................ 8 What isaDatabase? Adatabase isanorganizedcollectionofdata. Theprimaryfunctionofadatabaseprogram is toenable theuser toput acollectionof information intosomespecificorder: alphabetical, numerical, chronologi- cal, orsomecombinationof the three. Thereare twokeyquestions that must beansweredbeforecon- structingadatabase: Whatinformationdoyouwantomaintain? Inwhatorderdoyouwanthisinformationorganized? Theanswerstothesequestionsdeterminehowyouwillstructureyourdatabase. CommonlyUsedTerms DatabaseProgram . The termdatabase isoftenused torefer toanentiredatabasemanagement system (DBMS). Forexample, thesoftwareprogramsAccess, dBase, FileMakerPro, andFoxBaseareoftenre- ferredtoasdatabaseprograms. MicrosoftExcelisusuallyconsideredaspreadsheetapplicationcontain- ingseveraldatabasefunctions. DatabaseFile. Withinagivenprogram, the termdatabase, ordatabasefile, hasamorespecificmean- ing. Itreferstoaspecificcollectionofdatawithasinglefocusortopic. Record. Adatabasefile isagroupofrecords that are identical instructure. Arecordcontains informa- tionaboutasingleiteminyourdatabase. Field. Each record ismadeupof aseriesofieldswhichstore individual bitsof information insidea help.unc.edu Copyright2002, TheUniversityofNorthCarolinaatChapelHillAcademicTechnologyandNetworks. Allrightsreserved. May bereproducedinanymediumfornon-commercialpurposesinaccordancewiththeCopyrightPolicyofTheUniversityofNorth CarolinaatChapelHillathttp://www.unc.edu/campus/policies/copyright.html.

Upload: muhammad-fahim-khan

Post on 18-Nov-2014

432 views

Category:

Documents


1 download

DESCRIPTION

Concepts of Microsoft Office.

TRANSCRIPT

Page 1: Ms Access Concepts

Database ConceptsTable of Contents

What is aDatabase? ............................................................................................................................ 1CommonlyUsedTerms......................................................................................................................1TypesofDatabases ..............................................................................................................................2What Are the Parts of a Database Program? ....................................................................................... 2Identifying the Fields to Include ......................................................................................................... 3DatabaseStructure...............................................................................................................................4FieldLengths.......................................................................................................................................6DataStorage........................................................................................................................................6Relationality: Making Databases Work Intelligently .......................................................................... 7Data Entry and Display: Forms ........................................................................................................... 7Organization of Data (Sort Functions) ................................................................................................ 8Queries and Search Conditions (Report Functions) ............................................................................ 8

What is a Database?A database is an organized collection of data. The primary function of a database program is to enablethe user to put a collection of information into some specific order: alphabetical, numerical, chronologi-cal, or some combination of the three. There are two key questions that must be answered before con-structing a database:

What information do you want to maintain?

In what order do you want this information organized?

The answers to these questions determine how you will structure your database.

Commonly Used TermsDatabase Program. The term database is often used to refer to an entire database management system(DBMS). For example, the software programs Access, dBase, FileMaker Pro, and FoxBase are often re-ferred to as database programs. Microsoft Excel is usually considered a spreadsheet application contain-ing several database functions.

Database File. Within a given program, the term database, or database file, has a more specific mean-ing. It refers to a specific collection of data with a single focus or topic.

Record. A database file is a group of records that are identical in structure. A record contains informa-tion about a single item in your database.

Field. Each record is made up of a series of fields which store individual bits of information inside a

help.unc.edu

Copyright 2002, The University of North Carolina at Chapel Hill Academic Technology and Networks. All rights reserved. Maybe reproduced in any medium for non-commercial purposes in accordance with the Copyright Policy of The University of NorthCarolina at Chapel Hill at http://www.unc.edu/campus/policies/copyright.html.

Page 2: Ms Access Concepts

record.

Types of DatabasesThere are two main types of databases that you need to know about: flat-file and relational. As thename implies, a flat-file database consists of a single database file or table which contains all of the in-formation that you want to store about your topic. This type of database is ideal for a simple databasethat does not contain a lot of repeated information. A relational database, on the other hand, consists ofmultiple database files or tables linked together by at least one common field. For instance, a librarycard catalog might consist of an Author table, a Title table, and a Subject table. This type of structureeliminates the endless repetition of author and title information that would occur in a flat-file databasecontaining the same information. In turn, this structure makes data entry easier, as well as easing storageproblems on your hard disk.

What Are the Parts of a Database Program?In general, all database management programs have the same overall organization. Different types ofobjects perform specific tasks. Most database programs contain four main object types: tables, queries,forms, and reports.

What Are Tables?

Data are always stored in tables, and understanding the design of the tables in your Access database cansave you hours of work. Each table contains information about one subject, such as employees, membersof the class of 1994, or addresses. One table might store customer names and addresses while anotherstores customer orders. Tables are made up of records, which contain all of the information about a sin-gle entry, such as an employee or address. Each record is then subdivided into fields, which are thesmallest increments of useful data in your database. If you are making a mailing list, then you mighthave fields for First Name, Middle Name, and Last Name, rather than including only one field for a per-son's name. Visualize your table by imagining the fields across the top of your table as column headingsand then thinking of each record as a row in the table. Relational databases, like Access and FileMakerPro, use many tables that each store different information about a related subject

What Are Queries?

A query is a way of asking questions about data stored in your tables. A query's design tells the databaseengine exactly which data to retrieve. With queries you can look at selected data from one or more ta-bles without viewing all of the fields in each table and without having to save the data over again. Theonly parts of a query that most database management programs retain are the design parameters. Queriesare especially useful because they let you organize your data without tampering with the actual recordsthemselves. For example, you could use a query to alphabetize a mailing list or to select only residentsof Chapel Hill from a state-wide mailing list.

What Are Forms?

Like a paper form, an Access form or a FileMaker Pro layout collects and organizes information. In

Database Concepts Page: 2

Page 3: Ms Access Concepts

forms you can enter data into your database, display this data for review, and print it out. Forms are de-signed to make on-screen data entry and retrieval easier. In most database programs, you will almost al-ways use a form to enter and to edit data because you can enter information to be stored in more thanone table on a single form. Another advantage of using forms to enter and to edit data is that you look atonly one record at a time. If you enter data using tables, you will have to look at a confusing number ofrecords at once.

What Are Reports?

A Report provides a way to retrieve selected stored data and present that information effectively andmeaningfully. Reports are designed to be printed out rather than viewed on a computer screen, so theyneed to be carefully planned. Examples of everyday reports include mailing labels, invoices, receipts,sales summaries, and phone books. You can combine text, data, pictures, lines, boxes, graphs, and draw-ings to produce exactly the report you want. Fortunately, the latest versions of the big database packagesalso come with several pre-planned report layouts that you can set up quickly using Report Wizards.

Identifying the Fields to IncludeTo create your own phone book database, you need at least three bits of information for each person:Name, Address, and Phone Number. To make this database more usable, however, you need to furthersubdivide this information. The first thing you want to maintain is the name, since that is usually howlistings are ordered in the telephone book. Specifically, entries are ordered first by last name, then byfirst name. Each name, therefore, actually consists of two fields: Last Name and First Name. The nextthing you want to maintain is the address, but again, this information consists of smaller units. Tradition-ally, an address consists of a street number and name (Street), a city name (City), a state abbreviation(State), and a zip code (Zip): four separate bits of information. Finally, you want to maintain the phonenumber. Depending on how detailed you want your database to be, the phone number may consist of asingle field or a set of two fields, one containing the 3-digit area code and the other containing the7-digit number. If you do not anticipate ever organizing your records by area code (i.e., grouping allrecords with the same area codes together), there is no reason to make the phone number two fields.When creating a database, it is a good rule of thumb to keep the structure as simple as possible. Themore fields in a database, the longer it takes to process and store information. Assuming that you keepthe phone number as a single field, you have now created seven fields out of three bits of information:

At this point, you might choose to maintain additional information for each person, such as birthdate,

Database Concepts Page: 3

Page 4: Ms Access Concepts

whether you send a holiday card, and how many children the person has. This gives you three morefields for each record:

Now, you need to create a structure for your database using these ten fields.

Database StructureThe structure of a database specifies information about the fields maintained in the records of thatdatabase, including: the name of each field, the type of data maintained in each field, and the requiredlength (in terms of spaces) of each field. To help clarify this structure, you can use a grid such as this:

Field Names

The field name should be as concise and yet as descriptive as possible. Names should be one or twowords long, and should be some sort of key phrase indicating the type of information to be maintained inthe field. Note the field names used in the phone book example.

Field Types

Generally speaking, database software programs distinguish between different types of information,handling numbers and dates differently than textual information such as names. The most common fieldtypes are:

Database Concepts Page: 4

Page 5: Ms Access Concepts

Character Fields

Now, looking at the data stored in the first seven fields of your phone book database, you see that all ofthem (Last Name, First Name, Street, City, State, Zip, and Phone) should be defined as character fields.While it is obvious why Last Name, First Name, City, and State are defined as character fields, it maynot be as clear why Street, Zip, and Phone are. Street is a character field because it contains both nu-meric and alphabetic information (street number and street name). Zip and Phone are defined as charac-ter fields because although they are used to store numbers, those numbers will never be used in calcula-tions, i.e., never added, subtracted, multiplied or divided with any other numbers.

Numbers and Field Definition

It is important to be careful in defining a field as either numeric or character when dealing with num-bers. Once a field is defined as numeric, it can be used in calculations, even if you do not intend for it tobe. For example, if you defined the Zip field as numeric, you would run into problems when you entereda ten-digit zip code (zip-ext.). For example, in the Zip field, you type: 27599-3480, but when you pressEnter, the Zip field displays instead: 24119. What happened? The program, taking the zip field as nu-meric, thought a mathematical equation was being entered. It interpreted the dash (-) between 27599 and34800 as a minus sign and automatically performed a subtraction calculation, then displayed the result inthe field.

Other Fields

The remaining fields (Birthday, Card, and Children) are of different types. Birthday is a date field be-cause it stores a specific date. Card is a logical field because it asks the yes/no question "Send a holiday

Database Concepts Page: 5

Page 6: Ms Access Concepts

card to this person?" Finally, Children is a numeric field because it stores a number that might be used ina calculation (e.g., multiply the number of children by $20.00 to calculate amount of check to include inholiday card). Depending on the database program you use, you may have other field type options, oryou may be able to define a field type at a lower level. For example, some programs allow you to spec-ify the format in the number field (e.g., whole numbers or decimals; allowable number of decimalpoints).

Field LengthsMost database programs require you to specify the length of each field when you create a database. Theydo this to ensure that the stored information takes up no more space than it absolutely has to on yourhard disk, floppy disk, or network device. They also do this to minimize the amount of time it takes forthe computer to process your information. The key is to make each field only as long as its longest pos-sible entry.

Data StorageSince database software packages create database structures to store information in the smallest amountof space possible, you can extrapolate the length of individual records from the total length of all fields.From this, you can approximate the size of an entire database. Why is this important? Consider the fol-lowing two examples: 1. At the office, you are assigned to implement a database of approximately 200clients using the structure you have just created. 2. The University wishes to implement a database of750,000 alumni using your structure. Where are you going to store this information? Whenever you dealwith memory storage devices like floppy disks, hard disk drives, or network drives, you are automati-cally dealing with finite resources. These devices will store a certain amount of memory—and no more.A question you must pose in each example is "Do you have adequate space on your floppy disk/harddrive/network to store the database you're creating?"

You can approximate the amount of space your database files will occupy on your memory storage de-vices by multiplying the total of the field lengths by the number of records. The number returned willapproximate the amount of memory space (measured in bytes) required to store the information. For thefirst example, you take the number of clients, 200, and multiply that by the total field lengths, 145, to ar-rive at the number, 29,000. This means that you can expect your client database file to be approximately29,000 bytes, or over 29 kilobytes (Kb) in length. Should you have trouble fitting this on an emptyfloppy disk or on a hard disk? Not really. But in the second example, the number of alumni, 750,000,multiplied by the total field lengths, 145, returns a value of 108,750,000, for a file size of approximately109 million bytes, or 109 megabytes (Mb). Can this file be stored on a floppy disk? No. Can it be storedon a hard drive with a storage capacity of 50 Mb? No. Could it be stored on a hard drive with a capacityof 125 Mb? Still, probably not: remember, the hard disk has to have room on it not only for the databasefile in question, but also for the software package that lets you use it. Also remember the need for expan-sion: to this alumni database you should expect to add approximately 7,500 records every year. As a ruleof thumb, make sure your memory storage device has available memory of at least 10 times the size ofthe projected database, to permit adequate space for backup copies of the database file, along with reportforms and index files that accompany it. The first example would require a floppy disk or hard drivewith at the very least 260 Kb of memory free. The second example should be placed on a hard drive ornetwork device with around 1 billion bytes, or 1 gigabyte (Gb) of memory, available.

Database Concepts Page: 6

Page 7: Ms Access Concepts

Relationality: Making Databases Work IntelligentlyModern databases must be efficient in order for people to use them in their everyday tasks. The singlelargest source of inefficiency in databases is unnecessarily repeated data. A flat-file database will workjust wonderfully for an address book that contains only one address for each person, yet it does not workso well when several people on your mailing list use more than one address for their correspondence.You have two options: repeat the data in the same table or build a second table that is related to the firsttable by sharing a common field. You might want to break the phone book database file into a Namedatabase and an Address database. These two tables could then be linked together by sharing a commonfield, like Name ID#, in what is called a one-to-many relationship. This type of structure has two pri-mary advantages: facilitating data entry by removing those unnecessary repetitions and decreasing yourstorage needs by no longer needing to store repeated information on your hard disk. Every databasemanagement program provides an easy and intuitive way to create relationships between database files.

Data Entry and Display: FormsNow that you have a structure in place, you can input data. Most applications display a "blank" recordon the screen: a series of field names, listed vertically, each followed by an empty box, where you cantype in information. Generally speaking, you can enter information into some or all of these fields, anduse the arrow, Tab, or Enter keys to move back and forth between them. Most database software appli-cations also allow you to customize the display of information on the screen—to change the order inwhich the fields are displayed or to give fields different titles on screen (without changing the fieldnames themselves).

In addition, most database applications give you another way of looking at the data you enter. The aboveexample allows you to look at the contents of one record only. Most applications also let you browsethrough databases, and look at the contents of many records at the same time. For example, in thespreadsheet-like grid below, the contents of each record appears in a single row, while the columns showinformation from the fields.

Database Concepts Page: 7

Page 8: Ms Access Concepts

Organization of Data (Sort Functions)With this information entered, you can now organize it in a number of ways: alphabetically by last andfirst name, geographically by city and state, chronologically by birth date, logically by whether or notthey're on your regular mailing list. You may also need to organize the same information in combina-tions of these ways: alphabetically by name and by city, or keeping people in the same city together inalphabetical order by last and first name. In addition, you may need to maintain several orders simulta-neously, so that you can quickly move from one order to another and back, seeing information displayedfirst in one way, and then in another.

Most database applications let you sort the data or create indexes, separate files that arrange the infor-mation in a database in particular order. Most database applications let you create both single-field in-dexes (chronologically, by BIRTHDAY, for example) and multiple-field indexes (alphabetically byCITY, then LAST, then FIRST). In addition, most databases let you create and maintain more than oneindex for each database, so that you can quickly shift from one order to another. Indexes order informa-tion chronologically, numerically, alphabetically, or logically, depending on the fields included in the in-dex. Our database example, indexed alphabetically by city, would look like this:

Note that the database itself is not changed by using an index. The first record entered in the database re-mains record number 1. The only thing an index does is change the order in which records are displayed.

Queries and Search Conditions (Report Functions)Having entered information into the database and organized that information, you now consider ways toget that information out, usually in the form of reports. Sometimes, you need to print out the all informa-tion in a database to answer a question like "Who do you have in the database?" Most database applica-tions allow you to easily print out or display on screen a list of all records in a database. In this way, the

Database Concepts Page: 8

Page 9: Ms Access Concepts

applications enable you to generate customized reports, which display the fields of a database in the or-der you desire, on forms of your own design. Sometimes, though, you don't need all of that information.If you need to know only the names and addresses of the people in Chapel Hill to whom you send cards,you don't want to see the unrelated records and fields. For this reason, most database applications allowyou to select only the fields you are interested in for display. If you wish to see only name and addressfields, then you can select only those fields for display.

In addition, database applications allow you to select single or multiple criteria for database searches. Ifyou wanted the complete records for all people living in Chapel Hill, you would search on a single crite-rion: CITY = "Chapel Hill." However, you will often want to define your data set using more than onecriterion or condition. In database applications, you combine multiple conditions with some form of log-ical connectors—the concepts of "and," "or," and "not."

The AND Logical Connector

In the example above, you are interested in seeing the names and addresses of people in Chapel Hill towhom you send cards. This search has two conditions: (1) CITY = "Chapel Hill", and (2) CARD =" Y".If you perform searches of these conditions separately, you get the two separate sets of data. For exam-ple, your search for records where CITY = "Chapel Hill" results in the following data set.

On the other hand, your search for records where CARD = "Y" results in a different data set.

Neither of these searches alone gives you just the information you need. To accomplish that, you mustconnect the two conditions in a third search. If you wish to combine the two searches above to get a listof people in Chapel Hill to whom you send cards, you must perform a search of the database for recordsfor which the CITY field equals "Chapel Hill" AND the CARD field has a value of "Y". Such a searchprovides you with the following set of data.

Database Concepts Page: 9

Page 10: Ms Access Concepts

The OR Logical Connector

You need to be careful when using these logical connectors in your searches. Using an OR connector in-stead of AND will give you very different results. For example, a search where the CITY field equals"Chapel Hill" OR the CARD field has a value of "Y" would generate the following list of ten records, asopposed to the list shown above which contains only four records.

All of these records fit the condition: Each has either a CITY field equal to "Chapel Hill" OR a "Y"value under CARD.

Database Concepts Page: 10