U3 G 11
U3 G 11
DATABASE MANAGEMENT
Database management is a method used to organize data in a more effective way
for easy management and use of data.
3.1. Data Management Approaches
The first computer-based data management is a file-based data
management approach.
The database approach was introduced later and addressed the inherent
weaknesses of the file-based approach.
3.1.1 File based data management
File-based data management is an approach in which data is stored in separate
files without explicit relationships. Data in different files is managed by different
application programs.
Any change to data requires modification of the program that uses the data.
Changes made on the program may also require change in the file structure.
In file-based data management approach, each department creates and processes
its own files separately.
The file-based data management approach creates problems of data duplication
and data inconsistency.
3.1.2 Database approach to data management
In the database approach to data management, data is managed by a database
using a database management system (DBMS) software.
A database is a collection of logically-related data. It stores all organization’s data
in one repository.
DBMS is software that manages databases. DBMS is used to add new data, modify
data retrieve data and delete data in the database. DBMS essentially serves as an
interface between the database and end users or application programs. It ensures
that data is easily accessed by potential users.
The database management process has three main components.
1. At the bottom is the database which stores the actual data.
2. In the middle is a DBMS which manages the database.
3. At the top of the DBMS are application programs that use the database. The
application programs submit database query to the DBMS.
The database approach to data management provides many advantages to the
organization.
Data independence
Data sharing
Avoiding data redundancy
Improved data security
3.2. Data Model
Is the blue print of the database.
It is used as a guide to store data in a database.
It shows database entities, attributes and the relationships between the entities.
It also specifies what data to store in the database.
3.2.1 Basic Concepts in Data Modelling 11E A
1. Entities are basically people, places or events about which you want to store
data.
2. Attributes (Fields) are properties of an entity that are used to differentiate one
entity from other entity.
3. Tuples,( Records) Collection of related data items
4. A relationship is an association between entities.
The relationship between entities can take different forms:
1. One-to-one relationship: An instance of an entity has only one instance
(occurrence) in the other entity with which it is associated.
For example, a country and a capital city.
2. One-to-many relation: An instance in one entity is associated with many
instances in the other related entity.
For example a department called ‘Computer Science’ is associated with
multiple students.
3. Many-to-many relationship: Instances on both sides of the relationship are
associated with multiple instances of the other entity.
For example an employee may work in multiple projects. At the same time,
a project may have multiple employees assigned to it.
3.2.2 Entity Relationship Diagram (ERD)
ERD is used to visually represent a data model.
It has three main components namely entity, attribute and relationship.
o Entities are represented as a rectangle.
o Relationships represented as a line and
o Attributes are represented as ellipses.
As Figure 3.10 shows, student entity has student_id, name, age and address
attributes.
On the other hand, book entity has book_id, book_title, publication_year
attributes.
The two entities are related by ‘borrows’ relationship.
Figure 3.10
Student
Figure 3.12
3.2.4 Relational Database
Relational database is a type of database that contains logically
related set of tables.
Relational database is implemented using relational database
management system (RDBMS) software.
In RDBMS tables are identified by a unique field called a Primary
Key.
A Primary Key is a field which has a unique value (no two students
can have the same id) for each record.
The relational database uses Foreign Keys .
A foreign key is an attribute in a table that matches (link) the
primary key of another related table.
3. Enter the database name in the File Name input box. (use names that
properly describe the data stored in the database.)
Before other database objects are created, a table object must be created.
When you create a new table, Microsoft Access asks you to define table
fields. Table fields are entity attributes. One or more tables can be created in
one database.
• Each table name must be unique.
• The tables must also have two or more fields. Field names must be
unique in a table.
Follow the following steps to create a table in MS Access
1. Open a database file.
2. Click on Table Design button from the Create menu.
3. Enter field names for the new table such as Student ID, Sname, Sex,
Age and Grade_level .
4. Specify the data type of the field. The data type can be text, number,
date/ time, currency, etc. depending on the type of data that the field
is used to store.
5. When you finish, click on the Save button.
6. In the popup that is displayed, enter the table name and click on the
Ok button.
Notes
When you want to create a new table or add data into or modify an existing
table, you must first open the database in which you want to store your
database objects. This is important because there can be more than one
database in a single computer.
When you define a field to a table, you must specify the appropriate data type
for a Field name. The data type could be text, number, date and currency.
Data types are one form of validation mechanisms that ensure the
correctness of data in the database. If you set the data type as Text, it will not
accept its data as Number or any other type. Only text is a valid value to it.
To set the field as primary key, go to the table design view, select the field and
click on Primary Key ( ) button in the toolbar.
Follow the following steps in order to enter data into a database table:
1. Open a database if it is not already opened
2. Click on the table name and select Datasheet View from View in the toolbar. For
example, open student table.
3. Enter appropriate values for each field.
4. Enter all the records of the Student table .
Query is a database object that provides a custom view of data from one or more
tables. It is a way of searching for and compiling data from one or more tables. In MS
Access, data is retrieved through query by creating graphical query or writing
Structured Query Language (SQL) statements.
Follow the following steps in order to create a query in Microsoft Access:
1. Open a database where your database tables are stored
2. Click on Create menu button. You can create query using Query Wizard or Query
Design. Let us see how to create a query using Query Design option.
3. Click on Query Design button from Microsoft Access toolbar.
4. Select a table or tables from Show Table box from which you want to select records
for your query and click on OK bottom.
5.Select the fields in the Field row. For example, if you want to select only sname and sex
field, select sname in the first column and sex in the second column of the Field row.
6.Select Datasheet View from the toolbar to see your query results. If you do it
correctly, you get the following results.