Вы находитесь на странице: 1из 6

Laboratory Exercise 2:Creating and Using a New Access Database

This laboratory will provide practice in Creating a new Access database Creating tables-specifying fields and keys Specifying relationships between tables Entering records Editing records Creating q eries Creating si!ple reports Creating si!ple for!s

"or this lab# yo will create a database that keeps track of yo r ! sic collection and the friends who borrow ! sic fro! yo $

1 %pen Access and choose New, Blank Database fro! the panel on the right of the opening screen$ Choose yo r directory in the &Save in' window and change the filena!e fro! db1 to MyMusic$ (ake s re the filetype is set to (icrosoft Access Databases# and click on the Create b tton$

(ake s re the Tables ob)ect is chosen on the left panel of the MyMusic window$ Do ble click on Create Table in Design View$ *n the Table1 window that pops p yo will enter the field na!es and data types for all the fields of yo r table$ %n

the first line nder &"ield Na!e' type title$ *n the &Data Type' window on the sa!e line# click on the down arrow to see the available data types$ Choose text$ (ove down to the "ield +roperties window and type 35 as the field si,e$ (ove to the second line nder field na!e and enter the field na!e artist # then data type text# si,e 20$ (ake the third field dateAcquired and choose date/time as the data type$ (ake the fo rth field status with data type of text# si,e 10$ Then fro! the Access !en # choose "ile# Save As# and type in the table na!e Music$ -o will get a !essage re!inding yo that yo did not specify a pri!ary key and asking if yo wo ld like Access to create one for yo $ Choose yes$ Access will add an ID field with data type AutoNumber$ Close the table$

3. Create a second table of friends who !ight borrow yo r ! sic$ The first field is lastName# data type text 20$ This ti!e yo will create yo r own key consisting of the lastName$ To do so# !ove the c rsor to the col !n ) st to the left of lastName and click on the key icon on the Access toolbar$ Contin e to create the rest of the fields firstName text 15 areaCode text 3 phone Save this table as Friend$ text 7

4 Create a third table# Borrow# with fields ID Number lastName Long Integer text 20

dateBorrowed date/time dateReturned date/time This table needs a co!posite key consisting of ID and lastName. To create the co!posite key# !ove the c rsor to the first col !n to the left of ID and# holding the !o se b tton down !ove the !o se down one line to select both the ID and the lastName line$ .ith both highlighted# click the key icon$ Save the table as Borrow$

To create relationships between the tables click on the /elationships icon on the Access toolbar$ *t consists of three rectangles connected by lines$ *n the Show Table window that pops p# highlight Music# click on the Add b tton# highlight Borrow# click on Add# highlight Friend# click on Add# then click on Close$ The /elationship window opens# showing the three tables$ Click on lastName in Friend and drag to lastName in Borrow$ *n the Edit /elationship window that pops p# yo sho ld see both fields listed$ Check the bo0 &Enforce referential integrity' and then click on the Create b tton$ -o will see a line connecting the two tables with 1$$2infinity sy!bol3 on it$ The 1 sho ld be near the Friend table and the infinity sy!bol near the Borrow table$ 4*f this is not the case# yo !ade a !istake in designing the tables$ -o can click on the relationship line and press the Delete key to re!ove the relationship$ Then yo can ret rn to the table design and correct any error$5 Drag ID fro! Music to Borrow and create another relationship$ Choose Save and close the relationship window$

Do ble click on the na!e of the ( sic table$ Now yo will enter data into that table$ "or the ( sic table# the syste! will enter an *D 41#6#7$$5 a to!atically 4beca se yo allowed it to create an A toN !ber key for yo 5# b t yo sho ld enter the na!es of alb !s yo !ight have# the singer or artist# the date yo got the alb ! 4in the US# se the for! !!8dd8yyyy9 otherwise se the local convention for dates5# and the stat s$ -o can leave the stat s blank or enter borrowed,OK,scratched# or any appropriate string val e$ .hen yo have entered several alb !s# save the Music table and close it$

Enter data in yo r Friend table$ This ti!e lastName is the key$ -o ! st be caref l not to enter two records with the sa!e last na!e# and to re!e!ber the val es yo enter$

Now yo can enter data in the Borrow table$ Access will check to see that any ID yo enter !atches an ID in the Music table# and any lastName !atches one in the Friend table# so be s re the val es are valid$ The checking is done beca se we infor!ed Access of the relationships and asked it to enforce referential integrity$ Save this table$

Now yo will create a q ery that yo design yo rself$ Choose the : ery ob)ect$ Choose the option &Create q ery in design view$' *n the Show Table window# highlight ( sic# click on the Add b tton# highlight ;orrow# click on the Add b tton# highlight "riend and click on the Add b tton again$ Click on the Close b tton$ -o

are now in the q ery design window$ Choose whatever fields yo wo ld like to incl de in yo r q ery$ /e!e!ber yo can choose any of the tables# choose different fields# p t ! ltiple conditions on the sa!e criteria line to indicate AND# or p t conditions on different lines to indicate %/$ E0plore the options and create several q eries$ Note that if yo wish to co!pare strings the case ! st !atch e0actly# so be caref l of capitali,ation$ Design and e0ec te several q eries# saving the! nder na!es yo choose$ 10 Now yo sho ld design a report$ Choose the /eports ob)ect on the left panel$ Click on &Create report by sing wi,ard'$ Notice the drop-down window on the left that lists all the tables and q eries$ -o co ld choose any co!bination of these ob)ects for yo r report$ Choose one table$ "ro! the field list ) st below# highlight any field yo wish to incl de and press the right arrow b tton to select it for the report 4or si!ply do ble click on the field na!e5$ /e!e!ber that if yo accidentally choose an incorrect field# se the back arrow to deselect it$ After yo have chosen the fields yo wish fro! the tables and8or q eries# click on the Ne0t b tton at the botto! of the /eport .i,ard window$ -o have to option to view yo r data by vario s orders and gro ping levels# and to choose a style for yo r report$ Add a title that incl des by na!e$ Choose "inish to end the design and r n the report$

11 Choose the "or!s ob)ect fro! the ob)ects panel on the left$ Choose Create for! by sing wi,ard$ Choose one table# and click on the do ble arrow to select all its fields$ Choose all the defa lt specifications$ The for! sho ld pop p# showing the table<s

records one at a ti!e$ /e!e!ber yo can also enter data sing the for!$ After the last record# yo will see a blank for!# on which yo sho ld enter yo r own data$

12 Save all yo r changes and e0it Access$ Note= %nce yo have created a table# yo can always add new records by si!ply opening the table and entering the data$ -o can pdate an e0isting record by !oving the c rsor to the field to be changed and typing in the new val e$ -o can delete a record by highlighting it and pressing the Delete key or sing the !en options$ +ractice each of these operations on any table yo choose$ -o can print the table or any other ob)ect at any ti!e fro! the Access !en by choosing "ile# +rint$

Вам также может понравиться