Java Reference
In-Depth Information
is responsible for managing data and changes to that data. The reason we use a
database instead of simply a flat file is that a database can offer a lot of benefits,
primarily in the areas of integrity, performance, and security.
Integrity is probably the most important benefit, as without it not much else mat-
ters. If our data isn't consistent, reliable, and correct, then it is less valuable to
us—or possibly even useless. Databases achieve integrity by using strong data
types, enforcing constraints, and working within transactions.
Databases are strongly typed, which means that when a database table is cre-
ated, its columns are configured to store a specific type of data. The database
management system ensures that the data stored in the tables are valid for the col-
umn types. For example, a table might define a column as VARCHAR(25) NOT NULL .
This type ensures that the value is character data that is not of a length greater
than 25. The NOT NULL part of the definition means that the data is required and
so a value must be provided for this column.
In addition to strong typing, other constraints can be applied to tables. Such
constraints are usually broader in scope in that they deal with more than just a sin-
gle column. A constraint usually involves validation of multiple rows or possibly
even multiple tables. One type of constraint is a UNIQUE constraint, which ensured
that for a given column in a table a particular value can be used only once.
Another kind of constraint is a FOREIGN KEY constraint, which ensures that the
value in one column of a table is the same value as a similar column in another
table. Foreign key constraints are used to describe relationships among tables,
and so they are imperative to relational database design and data integrity.
One of the most important ways a database maintains integrity is through the
use of transactions. Most business functions will require many different types of
data, possibly from many different databases. Generally this data is related in
some way and therefore must be updated consistently. Using transactions, a data-
base management system can ensure that all related data is updated in a consis-
tent fashion. Furthermore, transactions allow multiple users of the system to
update data concurrently without colliding. There is a lot more to know about
transactions, so we'll discuss them in more detail in chapter 8.
Relational databases help us achieve a greater level of performance that is not eas-
ily made possible using flat files. That said, database performance is not free and
it can take a great deal of time and expertise to get it right. Database performance
can be broken into three key factors: design, software tuning, and hardware.
Search WWH ::

Custom Search