📄 ch02.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<TITLE>Ch 2 -- Table and Database Design</TITLE>
</HEAD>
<BODY BACKGROUND="../buttonart/bg1.gif" BGCOLOR="#FFFFFF">
<P>
<TABLE BORDER="0" WIDTH="600">
<TR>
<TD WIDTH="80" VALIGN="TOP"><IMG SRC="../buttonart/que.gif" WIDTH="75" HEIGHT="24" ALIGN="BOTTOM" BORDER="0"><BR>
<BR>
<A HREF="index.htm"><IMG
SRC="../buttonart/toc.gif" WIDTH="40" HEIGHT="40" ALIGN="BOTTOM" ALT="TOC" BORDER="0"
NAME="toc4"></A><BR>
<A HREF="ch01.htm"><IMG
SRC="../buttonart/back1.gif" WIDTH="40" HEIGHT="40" ALIGN="BOTTOM" ALT="BACK" BORDER="0"
NAME="toc1"></A><BR>
<A HREF="ch03.htm"><IMG
SRC="../buttonart/forward.gif" WIDTH="40" HEIGHT="40" ALIGN="BOTTOM" ALT="FORWARD"
BORDER="0" NAME="toc2"></A><BR>
<A HREF="index.htm"><IMG
SRC="../buttonart/home.gif" WIDTH="40" HEIGHT="40" ALIGN="BOTTOM" ALT="HOME" BORDER="0"
NAME="toc3"></A></TD>
<TD WIDTH="520" VALIGN="TOP">
<H2><FONT COLOR="#000077">Microsoft® Access 97 Quick Reference</FONT></H2>
<P>
<H1 ALIGN="CENTER"><FONT COLOR="#000077">- 2 -<BR>
Table and Database Design</FONT></H1>
<P>Before you enter any information in Access, you have to create a <I>table</I>
somewhere. A table is the foundation for all queries, forms, and reports. The container
for all these objects is the <I>database</I>.</P>
<P>In this part, you find tasks showing how to create your database file and the
tables that belong to the database. You follow steps for creating the basic building
blocks of a table--fields. In addition, you find reference information for setting
the <I>data type</I>, format, default value, size, and other properties of fields.
To speed up data retrieval and link to other tables, you can also <I>index</I> the
fields, set their <I>primary keys</I>, and create relationships between tables.
<H2><FONT COLOR="#000077"><B>Data: Blanks, Nulls, and Zero-Length Strings</B></FONT></H2>
<P>When entering information into your database records, you can leave data out of
a <I>field</I> if it is not available. However, a blank field can mean more than
one thing. It might signify that you don't know what the field's value is or that
a value for the field doesn't exist. You can leave a field blank if you don't know
what the value is (the value in this field is actually called a <I>Null</I> value).
If you set the Zero-length property, you can enter <B>"" </B>(two quotes)
in the field to indicate there is no value.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<DL>
<DD><B>1. </B>To set the Zero-Length property, open the <I>table</I> in <I>Design
View</I> and go to the field. Change the Allow Zero Length property to Yes.<BR>
<BR>
<B>2. </B>If you want to display text to inform you which fields have null versus
zero-length strings, click in the Format property. For text <I>data types</I>, enter
<I>Text Format</I>;<I>Null Format</I>; <I>Zero-length Format</I>. Where <I>Text Format</I>
is any formatting characters you would use for text, <I>Null Format</I> is what you
want nulls to look like, and <I>Zero-length format</I> is what you want zero-length
formats to look like. An example is <B>@;"Unknown";"None"</B>.<BR>
<BR>
For number data types, there are four options in the Format property: Number Format;
Negative Format; Null Format; Zero-Length Format.<BR>
<BR>
<B>3. </B>When finished, close and save the table design.
</DL>
<H2><FONT COLOR="#000077"><B>Data: Format</B></FONT></H2>
<P>In addition to decimal places (see "Decimal Places"), you can change
the format of a number so that all numbers look consistent in your <I>table</I>.
Numeric formats include dollar signs, percent signs, and commas. Date formats include
spelling the months or using numbers for the month, and how many digits to use for
the day and year. Text formats include capitalization.</P>
<P><I>Queries</I>, <I>forms</I>, and <I>reports</I> also enable you to change the
format places. On these objects you can change Format by right-clicking the <I>field</I>
or <I>control</I> in <I>Design View</I> and making the change on the <I>Property</I>
sheet in the forms and Reports part of this book. (See "Controls: Properties
Change " in the Forms and Reports part of this book.)
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<DL>
<DD><B>1. </B>Click a table name in the Tables tab of the <I>Database window</I>,
then choose the <U>D</U>esign button.
<P>
<DD><B>2. </B>Choose the <I>field</I> and click in the Format property on the bottom
half of the Table Design window.
<P>
<DD><B>3. </B>Choose one of the choices from the drop-down list.
<P>
<DD><B>4. </B>Click the Close (X) button on the Table Design window and choose <U>Y</U>es
to save the changes to the table design.
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>TIP:</B></FONT><B> </B>Text format types do not appear in
a drop-down list. Type <B>></B> to convert your entry to all uppercase. You can
also press F1 while you are in the Format property box for more detailed codes on
all <I>data types</I>.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Data Types: Changing</B></FONT></H2>
<P>When you create a <I>table</I>, you specify the <I>data type</I> for each <I>field</I>
in the Table <I>Design View</I>. Text, Number, Date/Time, Currency, and Yes/No data
types are self-explanatory. <I>AutoNumber</I>, formerly called Counter in previous
versions of Access, increments each <I>record</I> by one. While Text fields can only
contain up to 255 characters, <I>Memo</I> can include over 65,000 characters. <I>OLE</I>
<I>Objects</I> enable you to insert graphics, sounds, and other data types. The Lookup
data type will enable you to choose from a list of options. (See "Lookup Columns:
Create with Wizard.") The <I>Hyperlink</I> data type enables you to launch an
Access object (a table, form, query, and so on), another file in another application,
or go to a Web site. (See "Hyperlinks: Create Field.")
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>CAUTION:</B></FONT><B> </B>You can change a field's data
type but, depending on the particular conversion, this process can lead to data loss.
<HR>
</BLOCKQUOTE>
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<DL>
<DD><B>1. </B>Click the Tables tab of the <I>Database window</I>, click the table
name and choose the <U>D</U>esign button.
<P>
<DD><B>2. </B>Move to the field and click the Data Type column, then choose the data
type.
<P>
<DD><B>3. </B>Close the Table Design window and choose <U>Y</U>es when prompted to
save your change.
</DL>
<H2><FONT COLOR="#000077"><B>Data Types: Setting Defaults</B></FONT></H2>
<P>When you first create a field in Table Design View, the field is automatically
set to text and the default text field size is 50. If most of your fields are not
text or are a different size, you can change these defaults.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<DL>
<DD><B>1. </B>Choose <U>T</U>ools, <U>O</U>ptions and click the Tables/Queries tab.
<P>
<DD><B>2. </B>In the <U>D</U>efault Data Type drop-down box, choose the data type
you use most.
<P>
<DD><B>3.</B> Type your most used size for text in the Text box.
<P>
<DD><B>4. </B>In the Nu<U>m</U>ber drop-down box, choose the most used size for numbers.
<P>
<DD><B>5. </B>Choose OK when finished.
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>When you import data from another
source, you can type which names of fields will automatically be <I>indexed</I> in
the Auto<U>I</U>ndex on Import/Create text box.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Database: Create Blank</B></FONT></H2>
<P>A blank <I>database</I> is a database file that contains no <I>objects</I> or
data. It is an empty shell that you will use to add new <I>tables</I>, <I>queries</I>,
<I>forms</I>, and <I>reports</I>. If you want Access to create some of your tables,
forms, and other objects, see "Database: Create New with a Wizard."
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<DL>
<DD><B>1. </B>In a blank Access window or while the <I>Database window</I> from another
database is showing, choose the New Database button on the toolbar.
<P>
<DD><B>2. </B>Double-click the Blank Database template in the General tab of the
New <I>dialog box</I>.
<P>
<DD><B>3. </B>Enter a name in the File New Database File <U>N</U>ame <I>text box</I>,
specify the storage location of the file in the Save <U>I</U>n drop-down <I>list
box</I>, then choose the <U>C</U>reate button.
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>You can also press Ctrl+N to start
a new database from anywhere in Access. After you give the database a name, Access
closes the database that you were working on and opens a blank Database window.
<HR>
</BLOCKQUOTE>
<H2><FONT COLOR="#000077"><B>Database: Create New with Wizard</B></FONT></H2>
<P>You can create a new database that is blank or let the Database Wizard create
one for you that contains the objects you specify for it. The task, "Database:
Create Blank" describes the former process. This task describes the use of the
Database Wizard. Both procedures begin the same way.</P>
<P>When you use a wizard, Access enables you to choose from sample fields and then
create the <I>tables</I>, <I>queries</I>, <I>forms</I>, <I>reports</I>, and switchboards
for you. A switchboard is a <I>form</I> with buttons that help a user navigate through
the <I>database</I>. You can even have Access populate your database with sample
data to help you learn how different features work in the sample database.
<H3><FONT COLOR="#000077"><B>Steps</B></FONT></H3>
<DL>
<DD><B>1. </B>When you start Access the Introductory screen is displayed. Click <U>D</U>atabase
Wizard to open the Wizard.
<P>
<DD>If you already have Access opened, click the New Database button on the toolbar.<BR>
<BR>
<B>2. </B>Select the database from the Databases tab of the New Database <I>dialog
box</I>; then choose OK.
<P>
<DD><B>3. </B>Specify a location for the database file in your file system using
the Save <U>I</U>n drop-down <I>list box</I>; enter a new name for the database in
the File <U>N</U>ame <I>text box</I> of the File New Database dialog box; then choose
the <U>C</U>reate button. Access launches the Database Wizard.<BR>
4. Choose <U>N</U>ext to view the screen that lets you select additional fields and
sample data.
<P>Click the <I>check boxes</I> next to include optional fields (in italics) or uncheck
any other fields. Click the check box next to the Yes, Include Sample Data if you
want that feature, then choose <U>N</U>ext.
<DD><B>5. </B>On the next four wizard screens, select the styles you want for your
forms and reports, give the database a name that will appear on the switchboard,
and choose to open the database. On the last step, choose <U>F</U>inish.
</DL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>To see which sample database wizards
are available, look on the Database tab of the New dialog box. These wizards are
installed during the default setup. However, if you do not have the wizards, return
to setup (through your Office or Access CD), choose the Chang<U> </U>e Option button
while Microsoft Access is selected, and check the Wizards box.
<HR>
<HR>
<BR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>On the second to last step of the
new Database Wizard, you can include a picture on your reports by clicking the Yes,
I'd Like to Include a Picture check box, then choose the Picture button to specify
a picture file in the Insert Picture dialog box. Several graphic formats such as
bitmaps, icons, the Windows Metafile, TIFF, PCX, PICT, JPEG, GIF, and EPS are supported.
<HR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -