Sunteți pe pagina 1din 8

Lesson 2 In Chapters 3 and 4 you will learn how to set up the tables that are needed to store the

data for the Pass-ft Driving School. The Driving School syste is based on four tables. Student Instructor Lesson Lesson Type In this chapter you will set up the Student Table. In Chapter 4 you will enter the data and set up the re aining tables. There are two stages to designing a table! ". Define the field na es that a#e up the table and declare the data type for each. $. Set the field properties for each field na e. Defining the field names and data types %ccess needs to #now the na e of each field in each table and what sort the data to e&pect. 'or e&a ple in the Student table( the student)s telephone nu ber ight have as its Field Name Tel *o. +ou also need to tell %ccess whether the Data Type is nu ber( te&t( date,ti e( currency etc. In this case it is te&t. Setting the field properties -nce you have na ed the table and defined each field with its data type( we can control the fields further by setting Field Properties. These properties tell %ccess how you want the data stored and displayed. 'or e&a ple a date could be displayed ".,/0,.4( ".th 1une "..4 or ".-1un-.4. Setting up the Student table "- 2oad Microsoft ccess. $- Select !lan" ccess Database and clic# on #$ The New Database %indo& appears. 3. *a e the file Dri'ingschool and clic# on (reate. The Database 3indow loads. This is the control center fro for s( reports and acros. which you can design tables( 4ueries(

Remember! The database window will loo# slightly different in %ccess .5. 4. Clic# on Tables 6it should already he selected7 and clic# on New The *ew Table window will appear. 8. Clic# on Design )ie& and clic# on #$. The Table Design 3indow appears. -nce you are in Table Design view you can start entering the details of the fields needed in the table. Defining the Field Names and Data Types ". 9nter tile first 'ield *a e Student ID and press T%: or ;9T<;* to field. ove to the Data Type

%fter entering the 'ield *a e you will notice 'ield Properties are displayed in the lower half of the window( we will enter these later.

$. Clic# on the Drop Down and select utoNumber 3. In the Description 'ield enter Student)s ID nu ber. This is optional and only for infor ation.

4. Co plete the field Names and Data Types as shown below for the Student table.
Field Name Student ID Title Surname Forename Address 1 Address 2 Address 3 Address 4 Tel No Date of Birth Sex Theory Test Date assed Theory Test ra"ti"al Test Date assed ra"ti"af Test ass lus #e$ Issued %ard Data Type AutoNumber Text Text Text Text Text Text Text Text Date/Time Text Date/Time !es/No Date/Time !es/No !es/No !es/No

8. Set the Student ID field to be the #ey field by clic#ing on the row selector for this field and clic#ing on the Pri ary =ey icon of the Table Design toolbar or clic# on 9dit( Pri ary =ey. % s all picture of a #ey appears to the left. of the 'ield *a e. +our Table Design 3indow should appear. 0. Save the table by closing the window or by choosing 'ile( Save. The Save %s dialogue bo& will appear. *a e the table Student. Naming tables 3hen saving tables so e %ccess users li#e to start the na e with tbl( e.g. tbl student. They would start 4ueries with *ry for s with frm( reports with rpt and acros with mcr. +ou ay wish to consider using this na ing convention. If the Table Design toolbar is not already on the screen insert it by clic#ing >iew( Toolbars( Table Design. During the course of setting up the table it is probable you will a#e a ista#e or decide to change to your table)s structure. +ou have a nu ber of editing options available. Inserting a field Clic# on the row selector of the field below the insertion point. Press Insert #ey on the #eyboard or clic# the Insert +o&s icon on the toolbar. Deleting a field Clic# on the row selector of the field to delete. Press the D929T9 =9+ on the #eyboard or clic# the Delete +o&s icon on the toolbar. a#e a

Mo'ing a field Clic# on the row selector of the field you wish to ove. Clic# again and drag to its new position - a blac" line ar#s the insertion point. (hanging the primary "ey field +ou can only have one pri ary #ey. If you have set the wrong field as the pri ary #ey( re ove it as follows? Clic# on the row selector on the correct field. Clic# on ,dit- Primary $ey or clic# the Primary $ey icon on the toolbar. Setting the field proprieties 3hen you clic# on a field in Design >iew its field properties are displayed in the lower half of the window. 3e will go through each field in the Student table and set its field property including input as#s where appropriate. Student ID ". 'ro the Database 3indow clic# on Tables( select the Student table and clic# on Design. $. The Student ID field should be the one selected. If not( clic# in the row selector for Student ID 3. In the 'ield Properties set 'ield Si@e to 2ong Integer 6it probably already is7. See 'igure 3."/. Title The Title field can only have the values Ar( Ars( Aiss and As. +ou can use the 2oo#up 3i@ard whenever we want to restrict the data entered Into a field to certain values. ". Clic# on the Title field na e. $. In the Data Type colu n clic# on 2oo#up 3i@ard 3. Clic# on .I &ill type in the 'alues that I &ant.. and clic# on Ne/t. 4. 9nter Ar( Ars( Aiss and As into the colu n( press T%: to ove to the ne&t row. 8. Clic# on *e&t and then clic# on Finish. 0. In the 'ield Properties set the 'ield Si@e to 0. 3hen you wish to input data into this field a co bo bo& 6drop-down bo&7 will give you the choice of Ar( Ars( Aiss or As. Surname- Forename- ddress 0 and ddress 2 ". Select the 'ield *a e Surna e and set the 'ield Si@e to $/( repeat for 'orena e. $. Select the 'ield *a e %ddress " and set the 'ield Si@e to 3/( repeat for %ddress $. ddress 1 The Pass-It Driving School is based in Derby. It is li#ely that li#ely that students will live in Derby. It will save ti e if we set the default value for the %ddress 3 field to Derby ". Clic# on the ddress field. $. In the Default >alue bo& of the 'ield Properties( enter Derby %ccess inserts speech ar#s around the te&t. 3. Set the 'ield Si@e to $/. ddress 2 The ddress 2 field is the student)s postcode. ". Clic# on the ddress 2 field na e.

$. Set the 'ield Si@e to "/. 3. Clic# on the Format property bo& and enter B. This will convert any lower case letters entered into upper case e.g. de34 $qy will beco e D934 $C+. 2ater you will see how to set an Input Aas# to a#e entering post codes easier. Tel No Select the 'ield *a e Tel No and set the 'ield Si@e to "8. *:( Telephone nu bers cannot be a nu ber field as they are li#ely to include a space or brac#ets. Date of !irth The student table uses three Date,Ti e fields. 3e will use the Short Date for at for each e.g. ".,/0,.4 ". Select the Date of :irth field. $. Clic# on the Format bo& in the 'ield Properties. 3. % drop down list appears. Choose Short Date. It is also possible to use the Input Aas# wi@ard to set a placeholder D,D , for each date entered. 4. Clic# in the Input Aas# property bo& and clic# the three dots icon at the end of the row or the !uild icon on the Table Design toolbar( you will be as#ed to save your table first. The Input Aas# 3i@ard window is shown as 'igure 3.$/. 8. Select the Short Date option and clic# on *e&t. 0. % choice of placeholders is offered. Clic# on *e&t and then clic# on Finish. 5. ;epeat this for the other two Date,Ti e fields. Theory Test Date and Practical Test Date. Se/ The Se& field can only have the values A and '. 3e can use the >alidation bo& in the 'ield Properties only to allow A or '. ". Clic# on the Se& 'ield *a e. $. In the >alidation ;ule bo& enter M or F. 3. In the >alidation Te&t bo& enter Se/ must be either M or F. 4. Save your table. Passed Theory Test- Passed Practical Test- Pass Plus +e* and Issued (ard fields %ll the above fields have already been set to 3es4No field types and no re4uired. Setting up Instructor Table This section provides a little student table. In particular! ore detail on a nu ber of the functions you et during setting up the ore field properties are

+ou now need to set up a second table called Instructor to store the details of the instructors. Set it up with the structure as shown in Table $
Field name Instru"tor ID Title Surname Forename Address 1 Address 2 Address 3 Address 4 4ome Tel No Data type AutoNumber Text Text Text Text Text Text Text Text Other information Set as rimary &ey 'oo(u) table *alues+ ,r- ,rs- ,s- ,iss Field Si.e / Field Si.e 20 Field Si.e 20 Field Si.e 30 Field Si.e 30 Default *alue 1 2Derby2 Field Si.e 20 field si.e110 and set Formal to 3 Field Si.e 15

,obile No

Text

Field Si.e 15

Save the table as Instructor and switch to Datasheet >iew Setting up Lesson Type Table

ode to enter the data

The third table will be the Lesson Type table( storing details of the lessons and the cost of each lesson. The structure is shown in Table 3.
Field name 'esson Ty)e %ost Data type Text %urren"y Other information Set as rimary &ey Field Si.e 25

Setting up Lesson Table The fourth table will be the Lesson table. This is the table that lin#s all the other tables together and stores details of lessons boo#ed with the driving school. Its structure is shown in Table 8.
Field name 'esson No Student ID Instru"tor ID Date Start Time 'en6th of 'esson %olle"tion oint Dro):;ff oint 'esson Ty)e Data type AutoNumber Number Number Date/Time Date/Time Number Text Text Text Other information Set as rimary &ey field 'on6 inte6er 'on6 Inte6er Format+ Short Date and set In)ut ,ash Format+ Short Time and set In)ut ,as(7 Inte6er and set *alidation rule as Bet8een 1 and 9 Default *alue : 24ome Address2 Field Si.e 30 Default *alue 1 24ome Address2 Field Si.e 30 'oo(u) table *alues <see belo8=+ Introdu"tory- Standard- ass lusTest Field Si.e 25

*:. 3hen you run the 2oo#up 3i@ard choose to type the values in but you could loo# up the values fro the table 2esson Type. More about Table structure This section provides a little student table. In particular! Data types 'ield properties Input as#s 'or at field properties Default field properties >alidation ;ules %ccess has different data types available to store different #inds of data. They are shown in Table 0. Data type Te&t Meaning This is the default setting. <sed for shorter te&t entries. Can be a co bination of te&t( nu bers( spaces and sy bols. Aa&i u length $88 characters but you can set rt to less using the 'ield Si@e property <sed for longer te&t entries. Aa&i u length 08(838 charactersE <sed to store nu eric data This stores a data or a ti e or a date and the ti e. There are several ore detail on a nu ber of the functions et during setting up the

Ae o *u ber Date,Ti e

Currency %uto*u ber

+es,*o -29 -bFect

for ats for a date,ti e field. Aonetary values. *or ally in the <= this will be set to pounds and wor# to $ deci al places. %n %uto*u ber field will nu ber records auto atically as you enter ore data. The field acts as a counter. Duplicates are avoided and so %uto*u ber fields are Ideal as the hey field. %n %uto*u ber cannot be edited and when an %uto*u ber record is deleted %ccess does not allow you to go bac# and reuse this nu ber. -nly allows logical values such as +es,*o. True,'alse %n obFect lin#ed to or e bedded in a Aicrosoft %ccess table. This ight be an i age or a sound or a file created In another pac#age such as Aicrosoft 9&cel or Aicrosoft 3ord. % hyperlin# address. This can be lin#ed to! ". an obFect in your %ccess file( e.g. another table $. another locally stored file 3. a web page 4. an e- ail address This data type creates a :-H so that you can choose a value fro down bo&.

Gyperlin#

2oo#up 3i@ard

a drop

Field properties Table 5 describes the range of field properties. Property Description 'ield Si@e This is used to fi& the a&i al length of a te&t field. The default value is 8/ characters. The a&i u length is $88. 'or at This fi&es how data can be displayed( for e&a ple dates can be displayed in any different for s such as "3,/",/" or "3 1an /" or "3 1anuary $//". Input Aas# Caption Default >alue >alidation ;ule >alidation Te&t ;e4uired Inde&ed %llow Iero 2ength This sets a pattern for the data to be entered into this field. This is the field label in a for or report. This is the value entered into the field when the record is created It is usually left blan# but can be very powerful. This defines the data entry rules. This is the error essage if data is invalid This indicates whether an entry ust be ade or not. If an entry is re4uired( it is best not to set this property until the database is fully wor#ing. This allows data to be stored in the order of this field which speeds up searches. This Is used with te&t fields to decide whether records in that field are allowed to contain @ero length or e pty te&t strings(

Setting input mas"s Input as#s a#e data entry easier. They display on screen a pattern the data to be entered into a field. 'or e&a ple you ay be given the pro pt -,-,-- to enter the date. They are suitable for data that always has the sa e pattern such as dates, times, currency and also for codes li#e *ational Insurance nu bers( stoc# nu bers or postcodes.

Characters for input as#s you are li#ely to use are as follows! / % nu ber 6/-.7 must be entered . % nu ber 6/-.7 may be entered J % nu ber( K or - sign or space ay be entered 2 % letter %-I must be entered L % letter %-I may be entered % % letter or digit ust be entered a % letter or digit ay be entered c %ny character or space ay be entered M %ny character or space usE be entered N %ll characters to the right are changed to lower case B %ll characters to the right are changed to upper case ,/amples of input mas"s National Insurance number in the <= ust be or the for !021256( %ll letters are in capitals. Its input as# would be 7LL888888L 6it ust be $ letters followed by 0 nu bers and " letter7. postcode consists of one or two letters( then one or two nu bers( then a space( a nu ber and two letters. %ll the letters ust be capital letters. 9&a ples are !l 0!! or D,01 #LL- The input as# would lie 7L98: DLL. (ar registration numbers such as 3"$8 GOS could have 7L888 LLL as an input dri'ing licence no. of the for an input as#. as#.

:9S3/"8/$P$ A:.:A could have 7LLLLL;888888;LL8LL as as# ight be 8 <888<8888-

Product codes of the for at %$C-"$3-4805( % possible input

Input as#s are very powerful and need a lot of thought. It is possible to use the Input Aash 3i@ard to set up an input as# for a field. %t this stage you ay wish to ignore input as#s unless you #now the e&act for at of the input data. The Format field property The for ats supplied with %ccess will suit practically all your needs. Gowever it is possible to set a custo ( for at of your own. Two co only used e&a ples follow! 7 N will change te&t entered in the field to upper case will change te&t entered in the field to lower case

Note There is a significant difference between the 'or at and Input Aash field property. The 'or at property affect the data in the field after it is entered( e.g. if you enter "4,/5,.. into a 2ong Date for at field( It will appear as "4th 1uly ".... The Input Aas# property controls and restricts data entry. %n Input Aas# set to -,-,-- will only accept dates in the for at "4,/5,.. The default field property Default values are added auto atically when you add a new record. 'or e&a ple in a table of na es and addresses you ight set the County field to Derbyshire. Derbyshire then appears auto atically each ti e a new record is added and the user can either leave it or change it to so ething else.

+ou can also use e&pressions in the field property. Typically =Date>? will return the current date fro your PC. In a 2ibrary :oo# 2oaning syste ( the default value for the Date of Loan field could be sot to =Date>? and si ilarly for the Date of +eturn- the default value could be set to =Date>?@02 6assu ing a "4 day loan period7 Setting 'alidation rules >alidation rules allow you to control the values that can be entered into a field. :y setting the validation te&t property you can choose the essage that is displayed if the validation rule is bro#en. 'or e&a ple( if you want to enter in the 2esson 2ength field nu bers between " and P( the following validation rule will be used! 7=0 nd A=B If user input nu bers out of this range( you can avert it using Validation Text A number between 1 and 8 must be entered Special operators can be used to generate the validation rules! N NQ B BQ Q NB In :etween 2i#e 2ess than 2ess or e4ual Oreater than Oreater or e4ual 94ual to *ot e4ual to Test for RQS to any ite fro a list test for a range of values. The two values separated by %nd operator Tests a te&t or e o field to atch a pattern string of characters Possible 'alidation te/t 9nter a salary greater than P///T input dates before /" 1anuary $//" the date ust be after todaySs date si@es ust be S( A or 2 %ge ust be less than 35 Code ust 8 characters( starting with % Orades ust be %( :( or C essage!

)alidation rule BP/// NJ/",/",/"J BDate67 RSS or RAS or R2S :etween / and 30 2i#e R%LLLLS In 6R%S(S:S( RCS7

S-ar putea să vă placă și