P. 1
Database Design (2004) 527p

Database Design (2004) 527p

|Views: 387|Likes:
Published by Nikolive Bannya

More info:

Published by: Nikolive Bannya on Jan 10, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/13/2013

pdf

text

original

As the table list is derived from the entity list,the field listfor each table is derived from the
attributes listed for the associated entity. Again,most of this work should be done during logi-
cal modeling,but it should be refined and finalized during physical design.

As discussed,when listing and defining columns,you must establish the following information:

•Name of the column

•Data type

•Nullability

•Key values

•Applicable constraints

•Allowed data values

•Allowed duplicate values

The following subsections define column specifications for the EMPLOYEES table (refer to
the EMPLOYEE entity in Figure 11.2). The EMPLOYEE entity in the figure lists the follow-
ing attributes:

EMP_ID

NAME

ADDRESS

CITY

STATE

ZIP

PHONE

MGR_ID

DEPT_ID

Column Names

As explained,column names should be descriptive,concise,and represent the lowest level of
data associated with an instance in the entity or table.

The column names are based on the attribute names but are refined as necessary during table
design. For example,study the following refined column list:

EMP_ID

L_NAME

F_NAME

M_INIT

Designing Tables

CHAPTER11

11

D

E
S
I
G
N
I
N
G

T

A
B
L
E
S

275

16 7583 CH11 10/25/00 4:58 PM Page 275

ST_NUM

STREET

APT

PO_BOX

CITY

ST

ZIP

AREA_CD

PHONE

MGR_ID

DEPT_ID

The name has been broken out into its smallest components (last,first,and middle),the
address has been broken down (street number,street,apartment,and P.O. box),and the area
code has been separated from the phone number. Notice that all columns are no longer than
they really need to be,yet it is still easy to figure out how columns are associated with the
data.

Data Types

Given the previous column list,data types should be established,as follows:

Column Name

Data Type

EMP_ID

NUMBER(5)

L_NAME

VARCHAR2(20)

F_NAME

VARCHAR2(20)

M_INIT

VARCHAR2(1)

ST_NUM

VARCHAR2(10)

STREET

VARCHAR2(20)

APT

VARCHAR2(5)

PO_BOX

VARCHAR2(10)

CITY

VARCHAR2(30)

ST

VARCHAR2(2)

ZIP

VARCHAR2(5)

AREA_CD

VARCHAR2(3)

PHONE

VARCHAR2(7)

MGR_ID

NUMBER(5)

DEPT_ID

NUMBER(2)

Designing the Database

PARTIII

276

16 7583 CH11 10/25/00 4:58 PM Page 276

A few things might surprise you about the data types selected for the columns in this list. For
instance,why are columns such as AREA_CD,PHONE,and ZIP not assigned numeric data
types? Although these columns will always contain numeric values,they are never treated as
numbers,which means they are not used in calculations or summaries. The EMP_ID column is
defined as numeric because a value will be generated by the database for the column for each
row of data.

NULLValues

Now,it’s time to determine where NULLvalues are allowed. The keyword NULLindicates that a
column is optional or may contain NULLvalues. The NOT NULLkeyword indicates that data is
required for the column for all rows of data,meaning that NULLvalues are not allowed.

Column Name

Data Type

Nullability

EMP_ID

NUMBER(5)

NOT NULL

L_NAME

VARCHAR2(20)

NOT NULL

F_NAME

VARCHAR2(20)

NOT NULL

M_INIT

VARCHAR2(1)

NULL

ST_NUM

VARCHAR2(10)

NULL

STREET

VARCHAR2(20)

NULL

APT

VARCHAR2(5)

NULL

PO_BOX

VARCHAR2(10)

NULL

CITY

VARCHAR2(30)

NOT NULL

ST

VARCHAR2(2)

NOT NULL

ZIP

VARCHAR2(5)

NOT NULL

AREA_CD

VARCHAR2(3)

NOT NULL

PHONE

VARCHAR2(7)

NOT NULL

MGR_ID

NUMBER(5)

NULL

DEPT_ID

NUMBER(2)

NOT NULL

The way this table is designed so far,address-related columns must be defined as NULL
(optional) because an employee may use a P.O. box instead of a home address. It is possible
that any or all address-related columns will be used for a particular individual. MGR_ID is
defined as NULLbecause all employees will not have a manager (that is,if the highest-level
manager is considered).

Key Values

Key valuesmust now be determined or verified if already determined by the ERD. Key values
are related to primary keys,foreign keys,and unique keys. In the following example,notice that

Designing Tables

CHAPTER11

11

D

E
S
I
G
N
I
N
G

T

A
B
L
E
S

277

16 7583 CH11 10/25/00 4:58 PM Page 277

an SSN column has been added. Because all social security numbers must be unique,a unique
key for the SSN column has been designated to eliminate the chance for duplicate values.

Column Name

Data Type

Nullability

Keys

EMP_ID

NUMBER(5)

NOT NULL

PRIMARY

SSN

VARCHAR2(9)

NOT NULL

UNIQUE

L_NAME

VARCHAR2(20)

NOT NULL

F_NAME

VARCHAR2(20)

NOT NULL

M_INIT

VARCHAR2(1)

NULL

ST_NUM

VARCHAR2(10)

NULL

STREET

VARCHAR2(20)

NULL

APT

VARCHAR2(5)

NULL

PO_BOX

VARCHAR2(10)

NULL

CITY

VARCHAR2(30)

NOT NULL

ST

VARCHAR2(2)

NOT NULL

ZIP

VARCHAR2(5)

NOT NULL

AREA_CD

VARCHAR2(3)

NOT NULL

PHONE

VARCHAR2(7)

NOT NULL

MGR_ID

NUMBER(5)

NULL

FOREIGN

DEPT_ID

NUMBER(2)

NOT NULL

FOREIGN

Key values can be either natural or artificial when referring to primary keys.A natural value
refers to a value that is actually part of the organization’s data set. For instance,if you were to
use SSN as the primary key for this table,you would have a natural key because each SSN is
actually data. However,in this case an artificial key called EMP_ID is used. EMP_ID does not
represent any important data; it is only a numeric value that is generated by the system to
uniquely identify every row of data in the table.

Designing the Database

PARTIII

278

The allowance of duplicate values is handled primarily by primary key constraints and
unique constraints.

NOTE

16 7583 CH11 10/25/00 4:58 PM Page 278

Column Constraints

In addition to primary key,foreign key,and unique constraints,other constraints may be cre-
ated in order to control the integrity of the data stored in the tables. Check constraints can be
placed on columns to identify a static list of valid values for column data. Constraints can also
be placed at the application level as a checks-and-balances system for enforcing data integrity
at the database level.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->