Sunteți pe pagina 1din 5

What Is an Oracle Relational Database?

by Tim McLellan
Copyright 1994. All Rights Reserved.

This article is available for personal and public non-commercial use and may be
referenced or reproduced, in whole or in part by any means, without further permission
from the author. We only ask that you exercise due diligence in ensuring the accuracy of
the materials reproduced and that the author be credited for the work.

Contents
- What is a Database?
- Oracle Tables
- Primary Keys
- Relational Databases
- Foreign Key
- Lookup Table
See Also
- Data Modeling: Finding the Perfect Fit

What is a Database?
A database management system, or DBMS, gives the user access to their data and helps
them transform the data into information. Such database management systems include
dBase, Paradox, IMS, and Oracle. These systems allow users to create, update, and
extract information from their databases. Compared to a manual filing system, the biggest
advantages to a computerized database system are speed, accuracy, and accessibility.

A database is a structured collection of data. Data refers to the characteristics of people,


things, and events. Oracle stores each data item in its own field. For example, a person's
first name, date of birth, and their postal code are each stored in separate fields. The name
of a field usually reflects its contents. A postal code field might be named POSTAL-
CODE or PSTL_CD. Each DBMS has its own rules for naming the data fields.

A field has little meaning unless it is seen within the context of other fields. The postal
code T6G 2H1, for example, expresses nothing by itself. To what person or business does
it belong? The postal code field is informative only after it is associated with other data.
In Oracle, the fields relating to a particular person, thing, or event are bundled together to
form a single, complete unit of data, called a record (it can also be referred to as a row or
an occurrence). Each record is made up of a number of fields. No two fields in a record
can have the same field name.
During an Oracle database design project, the analysis of your business needs identifies
all the fields or attributes of interest. If your business needs change over time, you define
any additional fields or change the definition of existing fields.

Oracle Tables

Oracle stores records relating to each other in a table. For example, all the records for
employees of a company would be stored by Oracle in one table, the employee table. A
table is easily visualized as a tabular arrangement of data, not unlike a spreadsheet,
consisting of vertical columns and horizontal rows.

+----------------------------------------------------------------------
-----+
| EMPLOYEE
|
+-----------+--------------+--------------+--------+-------------
+----------+
| EMPL_ID | NAME_FIRST | NAME_LAST | DEPT | POSITION |
SALARY |
+-----------+--------------+--------------+--------+-------------
+----------+
| 1 | Horace | Slate | 1 | Owner |
29 |
| 4 | Fred | Flintstone | 2 | Excavator |
13 |
| 5 | Barney | Rubble | 2 | Laborer |
12 |
| 7 | Joe | Rockhead | 3 | Laborer |
11 |
| 11 | Shelly | Gravel | 1 | Secretary |
12 |
+-----------+--------------+--------------+--------+-------------
+----------+

A table consists of a number of records. The field names of each record in the table are
the same, although the field values may differ. Every employee record has a salary field,
called SALARY. The values in the SALARY field can be different for each employee.

Each field occupies one column and each record occupies one row. In each column of the
table, you put a specific category of information for the employees, such as their ID
number, first name, and position. Each row in the table contains the information relating
to a specific employee, together as one record. Each record is a unique entry and is
independent of any other record in the table. The EMPLOYEE table, for example,
contains records for Barney Rubble and Shelly Gravel. Although both records are part of
the EMPLOYEE table, the data contained within them is independent of each other.
There is no relationship between Barney's and Shelly's salaries.

After the analysis of the business requirements, the database design team defines the
necessary tables. Different tables are created for the various groups of information. An
EMPLOYEE table is created for employee information, a DEPARTMENT table is
created for department information. Related tables are grouped together to form a
database. For example, a personnel or human resources application database includes
both the EMPLOYEE and DEPARTMENT tables and all other tables involved in the
application.

Primary Keys

Every table in Oracle has a field or a combination of fields that uniquely identifies each
record in the table. This unique identifier is called the primary key, or simply the key.
The primary key provides the means to distinguish one record from all the others in a
table. It allows the user and the database system to identify, locate, and refer to one
particular record in the table.

The database design team determines the best candidate field for the primary key. The
employee's first and last names together could be a primary key, that is until a new
employee with the same name is hired. Then the key would no longer be unique.
Sometimes the design team has to define a new ID number or code field, just so that a
table has a primary key. For the EMPLOYEE table, the primary key would likely be the
employee ID number.

Once a table has been assigned a primary key, Oracle won't allow more than one record
in the table with the same value for the primary key. No two employees can have the
same ID number.

Relational Databases
Sometimes all the information of interest to a business operation can be stored in one
table. For example, let's say the only data you need to maintain about your office supplies
is a description of each item, its supplier, and the quantity on hand. It would be enough to
have one office supply table with those data items as the fields. More often, though,
business applications involve many tables. In a typical personnel application, there might
be one table for employees, another for information about their hours of work, and
another for the departments in the company.

Oracle makes it very easy to link the data in multiple tables: matching an employee to the
department in which they work is one example. This is a key feature of a relational
database management system, or RDBMS. They store data in two or more tables and
enable you to define relationships between the tables. The link between the tables is
based on one or more field values common to both tables.

For example, the following diagram represents part of the EMPLOYEE table and the
entire DEPARTMENT table:

+-----------------------------+
+-------------------------------------+
| EMPLOYEE | | DEPARTMENT
|
+---------+------------+------+ +---------+----------------
+----------+
| EMPL_ID | NAME_LAST | DEPT | | DEPT_NO | DESCRIPTION |
LOCATION |
+---------+------------+------+ +---------+----------------
+----------+
| 1 | Slate | 1 | | 1 | Administration |
Bedrock |
| 4 | Flintstone | 2 | | 2 | Quarry |
Bedrock |
| 5 | Rubble | 2 | | 3 | Stockpile |
Redcliff |
| 7 | Rockhead | 3 | +---------+----------------
+----------+
| 11 | Gravel | 1 |
+---------+------------+------+

There is a department number field in both the EMPLOYEE and DEPARTMENT tables.
In the EMPLOYEE table, the department number represents the department in which the
employee works. In the DEPARTMENT table, the department number represents a valid
department within the business. In both tables, they are department numbers; in essence,
the contents of the DEPT field in the EMPLOYEE table represents the same thing as the
contents of the DEPT_NO field in the DEPARTMENT table. It's not necessary that the
linking fields have the same field names. What's important is their value and what they
represent.

The business is divided into departments. The departments are identified and stored in the
DEPARTMENT table. Each department is assigned a department number. The
relationship between the EMPLOYEE and DEPARTMENT tables is based on the
department number. Each employee works in one specific department. The employee's
department number is stored in the DEPT field of the EMPLOYEE table. An employee
cannot be assigned to a department that is not defined in the DEPARTMENT table. A
department can be defined in the DEPARTMENT table, yet have no employees assigned
to it.

Foreign Key

Remember that every table in ORACLE has a primary key a field or fields making each
record unique. In the employee table, the primary key is the employee ID number, and it
is stored in the EMPL_ID field. In the DEPARTMENT table, the department number is
the primary key and is stored in the DEPT_NO field.

The department number is also stored in a field in the EMPLOYEE table - the DEPT
field. The department number field links the EMPLOYEE table to the DEPARTMENT
table. This relationship is based on the department number field. Employee Flintstone
works in department number 2, Gravel works in department 1.
When a field in one table matches the primary key of another table, the field is referred to
as a foreign key. A foreign key is a field or a group of fields in one table whose values
match those of the primary key of another table. You can think of a foreign key as the
primary key of a foreign table. In the personnel database example, the DEPT field in the
EMPLOYEE table is a foreign key. The DEPT_NO field is still the primary key of the
DEPARTMENT table.

Lookup Table
When a foreign key exists in a table, the foreign key's table is sometimes referred to as a
lookup table. The DEPARTMENT table in our example is a lookup table for the
EMPLOYEE table. The value of an employee's department can be looked up in the
DEPARTMENT table.

In Oracle, on-line screens or forms, have the ability to display a list of lookup table
entries. The employee form could have a lookup list of departments from the
DEPARTMENT table. The user simply highlights the preferred department, and Oracle
automatically enters that department into the employee's record. This provides a means of
ensuring that only valid data is entered in the database. A user can only select a listed
department. Whether or not a lookup list is used in a form, Oracle will still check for a
valid department when one is entered. However, if the form displays the list of possible
departments, the user is less likely to enter an invalid department number.

Not only does Oracle allow you to link multiple tables, it also maintains consistency
between them. It can prevent you from deleting a department which still has employees
in it. Or if you change an employee's ID number, then all records of their work hours will
also reflect that change. Ensuring that the data among related tables is correctly matched
is referred to as maintaining referential integrity. This also applies to the previous
example where a user enters an invalid department number for an employee. Oracle won't
accept a department number that isn't in the DEPARTMENT table.

Oracle's relational databases represent a new and exciting database technology and
philosophy on campus. As the Oracle development projects continue to impact on
University applications, more and more users will realize the power and capabilities of
relational database technology.

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