0% found this document useful (0 votes)
23 views46 pages

As Chapter 10

Chapter 10 discusses the database approach, emphasizing that a database is more than just data collection, but an implementation of a theoretical method defined by ANSI's three-level model. It covers the roles of Database Management Systems (DBMS), Database Administrators, and the relational database model, including SQL usage for data manipulation and the importance of normalization and integrity rules. The chapter also explains relationships between tables, including one-to-one, one-to-many, and many-to-many relationships, and the significance of primary and foreign keys in maintaining data integrity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views46 pages

As Chapter 10

Chapter 10 discusses the database approach, emphasizing that a database is more than just data collection, but an implementation of a theoretical method defined by ANSI's three-level model. It covers the roles of Database Management Systems (DBMS), Database Administrators, and the relational database model, including SQL usage for data manipulation and the importance of normalization and integrity rules. The chapter also explains relationships between tables, including one-to-one, one-to-many, and many-to-many relationships, and the significance of primary and foreign keys in maintaining data integrity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Chapter 10

D AT A B A S E A N D D AT A M O D E L I N G
The database approach

Database in not just a collection of data but it


is an implementation according to the rule of
a theoretical method.
This basic concept has been developed by
ANSI in three level model.
Three Level of Database Storage
Database Management system

DBMS
The physical storage of the data is
represented as being on the disk.
The detail of the storage are known only at
the internal level, the lowest level of the
ANSI architecture.
This is controlled by DBMS software.
Database Administrator

 At the next level , the conceptual level , there is


only the universal view of the database.
 This is controlled by the Database administrator,
who has access to the DBMS.
 At the external level, there are individual users and
programmer views.
 Each view has an external schema describing
which part of database are accessible.
 A view can support a number of user programs.
The Relational Database Management System (RDBMS)

 This model uses relationship between tables using


primary keys, foreign keys and indexes.
 Comparatively faster because of its relational
model.
 Used for huge applications using complex and
large amount of data
 Keys and indexes are used in the tables to avoid
redundancy.
 Example RDBMS are SQL Server, Oracle , MySQL,
MariaDB, SQLite.
Functions of RDBMS
SQL(Structured Query Language )

SQL is a programming language used to


search and query databases.
SQL gives you the ability to customize your
queries. It is often used within database
programs
SQlite and MySQL are popular open source
database applications. If you use a blog site,
it is very likely that MySQL has been running
behind the scenes to store entries as records
and allow you to add, edit and delete blog
posts.
SQL Syntax
Data Definition Language (DDL)

 Data Definition Language (DDL) is the part of SQL provided


for creating or altering tables.
 These commands only create the structure. They do not put
any data into the database
DDL (Data Definition Language )
Data Manipulation Language (DML):

 Data Manipulation Language (DM L) is used when a database is first


created, to populate the tables with data.
 It can then be used for ongoing maintenance. The following code

shows a selection of the use of the commands.


Select -----From -----Where
Result of Query
Working with WHERE Query
Result of query
Adding and editing data with SQL
Editing data
Past Paper examples (SQL)

1-to-many // 1 customer to/has many licenses

(ii) Describe how the relationship is created between the tables


CUSTOMER and LICENCE.
DML Queries
SQL Queries

CREATE DATABASE EMPLOYEES;


SQL Queries
Data Redundancy
How to reduce Data Redundancy?
What is a relationship?

 A relationship is formed when our two tables are joined together.


 Relationships make use of key fields and primary keys to allow the two tables to
communicate with each other and share their data.
What is a foreign key and what are they used for?
Composite Key
Compound key

 A compound key is similar to a composite key in that two or more


fields are needed to create a unique value.
 However, a compound key is created when two or more primary
keys from different tables are present as foreign keys within an
entity.
 The foreign keys are used together to uniquely identify each record.
 Compound keys are always made up of two or more primary
keys from other tables
Types of relationships

 The relationship between two linked tables can be


described in one of three ways:
 One-to-one
 One-to-many
 Many-to-many
One-to-one cardinality:
 One-to-one relationships occur when there is a direct one
to one link between data held on two different tables. For
example, each pupil in Scotland has their own unique
Scottish Candidate Number. It is not possible for a
pupil to have more than one number and it is not possible
for the same number to be allocated to two different
pupils. This is a one-to-one relationship:
Example of One-to- one Relationship
One-to-many cardinality

 One-to-many relationships exist where one instance of an entity can exist


lots of times in another entity.
 A good example relates to Pastoral Care or Guidance teachers in school. Here is an
entity holding details on each Pastoral Care/Guidance teacher.

 PastoralID is the primary key in the Pastoral Care Teacher entity.


 One Pastoral Care/Guidance teacher will have many pupils in their care. If we add a
field to our ‘Candidate’ entity, we can see that one Pastoral Care teacher can be
responsible for many pupils. We have added the primary key from the pastoral care
teacher entity.
 When we add a primary key from another table, it becomes a foreign key in this table.
One pastoral care teacher (PC001 -Miss McLuskey) has many pupils. The
above table shows both Hamish and Jenny have Miss McLuskey as their
Pastoral Care teacher. There is a one-to-many relationship between the
Pastoral Care Teacher entity and the candidate entity. One-to-many
relationships are illustrated by the following notation(s):
Many-to-many cardinality

Resolving many-to-many relationships In this example a third entity


called membership could be created. A compound key would be used to
uniquely identify each record in the new table
Many to Many relationships
One-to-Many
Many To Many
One to One
Normalization

 Apply the so-called normalization rules to check whether your


database is structurally correct and optimal.
 First Normal Form (1NF): A table is 1NF if every cell contains a
single value, not a list of values. This properties is known as atomic.
1NF also prohibits repeating group of columns such
as item1, item2,.., itemN. Instead, you should create another table
using one-to-many relationship.
 Second Normal Form (2NF): A table is 2NF, if it is 1NF and every
non-key column is fully dependent on the primary key. Furthermore, if
the primary key is made up of several columns, every non-key column
shall depend on the entire set and not part of it.
 For example, the primary key of the OrderDetails table
comprising orderID and productID. If unitPrice is dependent only
on productID, it shall not be kept in the OrderDetails table (but in
the Products table). On the other hand, if the unitPrice is dependent on
the product as well as the particular order, then it shall be kept in
the OrderDetails table.
Normalization

 Third Normal Form (3NF): A table is 3NF, if it is 2NF and the non-key
columns are independent of each others. In other words, the non-key
columns are dependent on primary key, only on the primary key and
nothing else.
 For example, suppose that we have a Products table with
columns productID (primary key), name and unit Price. The
column discount Rate shall not belong to Products table if it is also
dependent on the unit Price, which is not part of the primary key.
 Higher Normal Form: 3NF has its inadequacies, which leads to higher
Normal form, such as Boyce/Codd Normal form, Fourth Normal Form
(4NF) and Fifth Normal Form (5NF), which is beyond the scope of this
tutorial.
 At times, you may decide to break some of the normalization rules, for
performance reason (e.g., create a column called total
Price in Orders table which can be derived from the order Details records);
or because the end-user requested for it. Make sure that you fully aware of
it, develop programming logic to handle it, and properly document the
decision.
Integrity Rules

Integrity Rules
You should also apply the integrity rules to
check the integrity of your design:
Entity Integrity Rule

Entity Integrity Rule: The primary key


cannot contain NULL. Otherwise, it cannot
uniquely identify the row. For composite key
made up of several columns, none of the
column can contain NULL. Most of the
RDBMS check and enforce this rule.
Referential Integrity Rule:

Each foreign key value must be matched to a


primary key value in the table referenced (or parent
table).
You can insert a row with a foreign key in the child
table only if the value exists in the parent table.
If the value of the key changes in the parent table
(e.g., the row updated or deleted), all rows with this
foreign key in the child table(s) must be handled
accordingly. You could either (a) disallow the
changes; (b) cascade the change (or delete the
records) in the child tables accordingly; (c) set the
key value in the child tables to NULL.
Normalization Example

Here you see Movies Rented column has multiple values


1NF (First Normal Form) Rules

Each table cell should contain a single value.


Each record needs to be unique
2nd NF
3rd NF

You might also like