Basics of Database
Basics of Database
Basics of Database
CRISTY NAZARENO
The ease and speed with which data can be retrieved (read) from a database also depends upon
good database design. Data should be structured to allow specific items to be found and
retrieved quickly and efficiently. Any search performed any number of times should provide
consistent results.
Transactions
Modern databases support the concept of transactions. A transaction is a single operation or a
series of operations that retrieves or alters the data in a database. A successful transaction will
change the database in some way. The goal is always to change the database from one
consistent state to another consistent state. While a transaction is in process, the database may
enter an inconsistent state, but at the end of the transaction, the database is returned to a
consistent state.
A transaction can have either of two results it can be committed, or rolled back. If a transaction
finishes successfully, the results of the transaction are written to the database (committed) and
the end result is that the database attains a new consistent state. This is known as a commit.
Conversely, if there is a problem with the transaction and it does not complete successfully, it
will be aborted and the uncommitted data changes will need to revert back to their original
values. The formal term for reverting the transaction is a rollback, with the database being
placed back into the consistent state it was in before the transaction started.
A classic example of a transaction would be transferring money from one bank account to
another. Suppose Andy writes
Beatrice a check for Php 100 and you need to transfer money from Andy's account to Beatrice's
account. You subtract the Php 100 from Andy's account and add the Php 100 to Beatrice's
account. Both actions (subtracting the money from Andy's account and adding the money to
Beatrice's account) constitute one transaction of transferring the money. However, if a problem
occurs in the middle so that the Php 100 is subtracted from Andys account but Beatrices
account did not receive the Php 100, then there is an imbalance that needs to be corrected.
In a transaction, all the operations happen, or none of them happen. That is, all the operations
within that transaction are committed at the same time, but if the transaction is rolled back then
any of the operations that occurred inside the transaction will be reversed at the same time.
Databases should roll back any transaction that is open if the database encounters an error
situation.
ACID
ACID is an acronym for the four properties that are desirable for any effective transaction
system. These are:
Atomicity The transaction is a complete unit, and is executed in its entirety or not at all.
Consistency The transaction must change the database from one consistent state to
another consistent state. If an operation within the transaction would violate the
database's rules, the transaction is rolled back.
Isolation The transaction is independent from other transactions. That is, while a
transaction is in progress, no one else can see the data being affected, as this data may
CRISTY NAZARENO
be in an inconsistent state until the transaction is completed (committed). Any other user
reading the data while the AndytoBeatrice transfer transaction was in progress would see
the Php 100 either in Andy's account before the transaction or in Beatrice's account after
the transaction. An incomplete transaction (a state where the Php 100 is neither in Andy's
account nor in Beatrice's account) should not be visible to other users.
Durability Committed transactions are permanent and will not be lost if the power fails or
if the database restarts. Once a transaction has been committed, it cannot be rolled back.
The only way to undo a committed transaction is to execute another transaction that
reverses the changes made by the first transaction.
Security
Database security is accomplished through a combination of physical, network access and design
methods. Database servers, for example, can be made physically secure by setting them up in a
locked room where an access card is required to obtain entrance. You can also disable USB ports
on the server to prevent someone from copying data to removable storage media.
You can use the builtin security tools in your network to prevent unauthorized access to your
data. Additionally, through careful design, you can separate your data into categories that
different types of users need to access. You can then grant different levels of permissions to the
different types of users, thereby controlling access to your data.
Database Files
Microsoft SQL server uses three types of files to store the database:
Primary data files, with an .mdf extension, which contain user-defined objects, such as
tables and views, as well as system tables.
Secondary data files, with an .ndf extension, on separate physical hard disks to give your
database more room.
Transaction log files use an .ldf extension and dont contain any objects such as tables or
views.
Database Management System (DBMS)
Most users do not access the databases directly, Instead, users use a database
management system (DBMS) to access the databases indirectly. DBMS is a collection of
programs that enables you to enter, organize, and select data in a database.
Database Types
A database is a tool that stores data, and lets you create, read, update and delete the data.
Information storage is one of
the primary purposes of computers, and many different types of data storage systems have been
created over the many
years that computers have been in wide use. Filebased data storage systems represent the
earliest attempt at computerizing the traditional manual filing system. In a filebased database,
all the data is contained in one file. File-based
types include flat files and spreadsheets.
CRISTY NAZARENO
In contrast to filebased storage systems, relational databases store data in multiple tables
that are linked so that all data pertaining to a particular entity may be retrieved, even though
that data may be stored across several separate tables.
Hierarchical databases
A hierarchical database design is similar to a tree structure (such as a family tree). Each
parent can have multiple children, but each child can have only one parent. This type is
the oldest database type and is regarded as the first major influence on database
modelling. Examples are database created using MS Excel, FoxPro, etc. Below is an
example of hierarchical database
Relational databases
A relational database is similar to a hierarchical database in that data is stored in tables
and any new information is automatically added into the table without the need to
CRISTY NAZARENO
reorganize the table itself. Unlike in hierarchical databases, however, a table in a relational
database can have multiple parents.
Instead of a single table containing all the data, a relational database is a collection of
data organized as a set of formally defined tables. The tables can contain data that relates
to data held in other tables within the database, and this data can be retrieved from the
database in many different ways without the need to reorganize or restructure the
database tables themselves.
CRISTY NAZARENO
CRISTY NAZARENO
Features
An RDBMS is designed to provide general functionality and services for many different database
applications. There are numerous RDBMSs available for use on varying platforms. Most provide a
welldefined set of features which include the following:
The storage of data in a central repository (the database) that can be accessed by multiple
users.
Support for the use of Structured Query Language (SQL) to define and manipulate the
data. SQL is a language used to create professional, highperformance databases. You will
learn more about SQL later in this course.
Support for Data Definition Language (DDL), a subset of SQL used to define the data
contained in the database.
Support for data types (text, numeric, etc.) which must be defined for each column in a
table in advance. The database will not allow values of other types in the column, and will
not allow the data type to change without rebuilding the table.
The ability to enforce constraints, such as requiring that a delivery date be on or after the
current date, or requiring that a specific field contain a value.
Support for Data Manipulation Language (DML), a subset of SQL used to insert, update and
delete data.
The ability to preserve data consistency by preventing the insertion, modification or
deletion of records if such an action would result in inconsistencies.
Support for complex queries and functions.
The ability to restore the data to a previous state in case of a hardware or software failure.
Provision for protecting the data (e.g., a security system).
Support for a data dictionary (or system catalog) for describing the data within the
database.
Advantages and Disadvantages
The advantages to using an RDBMS include:
Management of data redundancy: As has been discussed, filebased systems tend to
store duplicated data. An RDBMS allows for the use of related tables, thereby eliminating
unneeded repetition of data. The RDBMS provides mechanisms for ensuring that updates
to redundant data across multiple tables are properly synchronized.
Consistency of data: Because of the ability to control data redundancy, the risk of
compromising the accuracy and consistency of the data is greatly reduced. If data appears
in more than one location in the database, the RDBMS can ensure that all instances of the
data remain consistent with one another.
Data sharing: In a filebased system, usually only one person has access to the file
containing the database. Because an RDBMS gathers data into a central repository,
several authorized users can have access to the data.
Concurrent data access: In a filebased system, usually only one person can access the
data at any time. Conversely, a database can be accessed by multiple authorized users
simultaneously.
Increased data integrity: The RDBMS provides mechanisms for defining the type of data
that can be held in a table or shared among tables. The RDBMS enforces the constraints
placed on the data in the database, thereby ensuring that the data is valid.
CRISTY NAZARENO
Increased data security: The RDBMS provides mechanisms to protect data from
unauthorized use. A database administrator (DBA) can define security measures, and the
RDBMS enforces those measures. These measures can include the use of user names and
passwords, restrictions on the type of operations a particular user can perform, and
restricted access to particular areas of the database for certain users.
Adherence to standards: The RDBMS supports the use of standard data access
methods, for example, through SQL. This adherence to standards provides developers and
programmers a standard way to access data from within any custom applications they
create.
Increased data backup and recovery: In a filebased system, the responsibility for
backing up and/or recovering data lies with the person who maintains the file. An RDBMS,
on the other hand, provides mechanisms for both backing up a database and recovering a
database in the event of hardware or software failure.
Entire courses are written on the proper steps for planning the design a database. Here, the
basic steps are described
very briefly.
The first phase in database design involves gathering information and creating a data
model. Before you pick up a pencil to sketch out your first table, be sure you understand the
requirements. Get a clear picture of what the database will be used for, what type of data it
needs to store, and what it needs to accomplish. Will the database track inventory, or customer
orders, or student grades? What types of reports might be expected?
During this phase of the process, you try to determine what type of data should go into
the database. Try to identify the specific entities that are involved. An entity represents a
specific instance of something you want to track, for example, a product or an order. If your
database needs to track information on customers, orders and inventory, it will probably include
entities for customer information, order information and inventory information. A good rule to
keep in mind when
determining an entity is this: One entity should represent one clearly defined thing, and nothing
else.
Each entity in the data model will contain particular attributes that describe characteristics of the
entity. For example, a customer entity would likely contain attributes such as a customer name,
customer identification number, and customer address. An inventory entity would likely contain
attributes such as an item identification number, items description, and price.
The data modeling process also involves determining how the entities relate to one
another. In practice, the task of creating the data model often generates more questions, which
in turn creates the requirement to perform more information gathering.
The second phase of database design involves creating a logical model. In creating a
logical model, entities are generally represented as tables, and attributes as table fields.
You determine how the data should be organized and diagram how the tables are related to one
another. You also identify the constraints that will keep the data valid and consistent.
The third phase of database design involves creating the physical database.
CRISTY NAZARENO
10