19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

348 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

’Close the recordset referring to TABLE1<br />

MyRec.Close<br />

’Open a recordset referring to TABLE2<br />

Set MyRec = T2.OpenRecordset<br />

’Create a record<br />

MyRec.AddNewMyRec(“FIELD2A”) = “alpha”<br />

MyRec(“FIELD2B”) = 2000<br />

MyRec(“FIELD2C”) = 1<br />

’Update the recordset<br />

MyRec.Update<br />

’Close the recordset<br />

MyRec.Close<br />

’Close the database<br />

MyDB.Close<br />

■ PRINCIPLES OF DATABASE DESIGN<br />

In order to design a database, you must decide how many tables to use, what fields to include<br />

in each table, what fields to make primary or foreign keys, <strong>and</strong> what validation criteria to<br />

specify. The programming paradigm “Plan first, code later” also applies to databases. Before<br />

you design a database, you first must underst<strong>and</strong> how the database will be used. For instance,<br />

you must know in what way <strong>and</strong> how often the user will update the data, <strong>and</strong> what types of reports<br />

the user will want to be generated from the database. Failure to plan ahead can be very<br />

costly.<br />

You have no doubt read about the “year 2000 crisis.” Databases designed in the 1960s<br />

<strong>and</strong> 1970s saved space by using just two digits to refer to each year. As a result, they cannot<br />

distinguish between the year 2000 <strong>and</strong> the year 1900. Correcting this oversight is predicted<br />

to cost government <strong>and</strong> industry billions of dollars.<br />

Good relational database design is more an art than a science. However, there are certain<br />

fundamental guidelines that the designer should keep in mind.<br />

Include the necessary data.<br />

After you have a clear picture of the types of reports the user must generate, you will<br />

know what fields <strong>and</strong> relationships to include. On the other h<strong>and</strong>, some data that seem relevant<br />

do not have to be kept.<br />

Be aware that data should often be stored in their smallest parts.<br />

For instance, city, state, <strong>and</strong> zip code are usually best stored in three fields. So doing will<br />

allow you to sort a mailing by zip code or target a mailing to the residents of a specific city.<br />

Avoid redundancy.<br />

The process of avoiding redundancy by splitting a table into two or more related tables<br />

is called data normalization. For instance, the excessive duplication in Table 11.5(a) can be<br />

avoided by replacing the table with the two related tables, Tables 11.5(b) <strong>and</strong> 11.5(c).<br />

TABLE 11.5(A)<br />

A Table with Redundant Data<br />

course section name time credits prerequisite<br />

CS102 1001 Intro to Databases MWF 8–9 3 CS101<br />

CS102 1002 Intro to Databases MWF 1–2 3 CS101<br />

CS102 1003 Intro to Databases MWF 2–3 3 CS101<br />

CS102 1004 Intro to Databases MWF 3–4 3 CS101<br />

CS105 1001 <strong>Visual</strong> <strong>Basic</strong> MWF 1–2 4 CS200

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!