PAPER2 - Option A - DATABASE - NOTES
PAPER2 - Option A - DATABASE - NOTES
PAPER2 - Option A - DATABASE - NOTES
Option A - Database
Paper-2 Option A Databases
2
Paper-2 Option A Databases
3
Paper-2 Option A Databases
4
Paper-2 Option A Databases
● Transactions: A transaction is a logical unit of work that consists of one or more database
operations that must be executed together as a single, atomic unit. Transactions ensure that
either all of the operations are completed successfully or none of them are completed at all. This
helps maintain data consistency by ensuring that the database remains in a consistent state,
● States: States refer to the condition of the database at any given time. Database management
systems use states to keep track of changes to the database, including additions, updates, and
deletions. The current state of the database is often referred to as the database's current state,
and it is important to maintain consistency across different states to ensure data integrity.
● Updates: Updates refer to changes made to the database, including additions, updates, and
deletions. Database management systems use update operations to make changes to the database
while maintaining data consistency and integrity. This is accomplished through the use of
locking mechanisms, which ensure that only one user can make changes to a particular record at
a time. This helps prevent conflicts and inconsistencies in the data.
By using transactions, states, and updates, database management systems can ensure data consistency
and integrity by ensuring that changes to the database are made in a controlled and consistent manner.
This helps prevent errors, conflicts, and inconsistencies in the data, which can lead to problems with
data quality and reliability.
5
Paper-2 Option A Databases
● Locking: Locking involves the use of locks to control access to data. When a user or
application accesses a particular record, a lock is placed on that record, preventing other users or
applications from accessing or modifying it until the lock is released.
● Time-stamping: Time-stamping involves assigning a unique timestamp to each transaction that
accesses the database. If two transactions attempt to modify the same data, the system can use
the timestamps to determine which transaction should be given priority.
● Multi-version Concurrency Control (MVCC): MVCC involves creating multiple versions of
a data record to allow multiple users or applications to access and modify the same data
simultaneously. Each user or application sees a version of the data that reflects the state of the
database at the time the user or application began the transaction.
Concurrency is an important concept in data sharing situations, and it is essential to manage
concurrency effectively to maintain data consistency, integrity, and reliability.
6
Paper-2
Paper Option A Databases
1. ATOMICITY: A transaction is atomic, which means that either all of its operations are
executed successfully or none of them are executed at all. This ensures that the database
remains in a consistent state.
2. CONSISTENCY: A transaction ensures that the database remains in a consistent state before
and after it is executed.
3. ISOLATION: Transactions
ions are executed in isolation from one another, which means that the
changes made by one transaction are not visible to other transactions until they are completed.
4. DURABILITY: Once a transaction is completed, its changes are permanently stored in the
database,
abase, even in the event of a system failure or other problem.
Database transactions are an essential concept in database management and are used to ensure data
consistency, integrity, and reliability.
7
Paper-2 Option A Databases
1. Query Functions: Query functions are used to retrieve data from the database. These functions
allow users or applications to search for specific data or to retrieve a subset of data that meets
certain criteria. Common query functions include SELECT statements in SQL and find()
functions in NoSQL databases. Query functions allow users to perform various types of data
analysis and reporting, such as sorting, grouping, filtering, and aggregating data. They are
essential for retrieving data from the database and for generating reports and insights.
2. Update Functions: Update functions are used to modify the data in the database. These
functions allow users or applications to add, update, or delete data in the database. Common
update functions include INSERT, UPDATE, and DELETE statements in SQL and save()
and remove() functions in NoSQL databases Update functions are essential for maintaining the
accuracy and integrity of the data in the database. They allow users to make changes to the data,
such as correcting errors, updating records, or deleting obsolete data. Update functions must be
used carefully to ensure that data consistency and integrity are maintained.
8
Paper-2 Option A Databases
9
Paper-2 Option A Databases
10
Paper-2 Option A Databases
SELECT *
FROM Customers
WHERE Country = 'Spain' AND CustomerName LIKE 'G%';
SELECT *
FROM Customers
WHERE Country = 'Germany' OR Country = 'Spain';
11
Paper-2 Option A Databases
INSERT/UPDATE/DELETE STATEMENTS
The INSERT INTO statement is used to insert new records in a table.
Insert Data Only in Specified Columns:
Databases require both query functions and update functions to be performed on them. Query functions
are used to retrieve data from the database and allow for data analysis and reporting. Update functions
are used to modify data in the database and ensure data accuracy and integrity. These two functions are
essential for managing data effectively in a database system.
12
Paper-2 Option A Databases
DATA VALIDATION:
Data validation is the process of checking whether the data entered into a system is accurate,
complete, and consistent with predefined rules and constraints. The purpose of data validation is
to ensure that the data entered into the system is correct and can be used reliably.
Data validation is typically performed when data is first entered into the system, and it involves
checking for errors, such as missing or invalid data, incorrect data types, or data that does not
conform to predefined rules and constraints. Data validation may be performed using automated
validation tools, such as regular expressions, or it may involve manual review and correction of
data.
13
Paper-2 Option A Databases
Data Verification:
Data verification is the process of checking whether the data in the database is accurate,
complete, and consistent with the original source. The purpose of data verification is to ensure
that the data stored in the database is a true representation of the original data source.
Data verification is typically performed on a periodic basis, such as during data migrations or
when integrating data from multiple sources. It involves comparing the data in the database with
the original source to ensure that it is accurate and complete. Data verification may involve
manual checks, automated tools, or a combination of both.
Data validation and data verification are both essential processes for ensuring the accuracy,
completeness, and consistency of data in a database system. Data validation checks the accuracy
and completeness of data when it is first entered into the system, while data verification checks
the accuracy and completeness of data stored in the database relative to the original source. By
performing both data validation and data verification, organizations can ensure that their data is
reliable, accurate, and useful.
14
Paper-2 Option A Databases
15
Paper-2 Option A Databases
Relational databases have often replaced legacy databases and network databases because they are
easier to understand and use. Relational databases are powerful because they require few assumptions
about how data is related or how it will be extracted from the database. As a result, the same database
can be viewed in many different ways.
An important feature of relational systems is that a single database can be spread across several tables.
This differs from flat-file databases, in which each database is self-contained in a single table.
Almost all full-scale database systems are RDBMS's.
● Data organisation and management: A DBMS helps organisations to store and manage large
amounts of data in a structured and organised manner, making it easier to find and retrieve the
data as needed.
● Data security and privacy: A DBMS provides a controlled environment for managing data,
enabling organisations to enforce data security and privacy policies and ensure that sensitive
data is protected.
● Data consistency and integrity: A DBMS helps to ensure that the data stored in the database is
accurate, consistent, and up-to-date, improving the quality of the data and supporting better
decision making.
● Data sharing and collaboration: A DBMS enables multiple users and applications to access
and use the same data, improving collaboration and data sharing across the organisation.
● Data analysis and reporting: A DBMS provides tools and functions for data analysis and
reporting, enabling organisations to gain insights into their data and make informed decisions
based on that data.
The purpose of a DBMS is to provide a centralised, controlled, and efficient environment for managing
data, enabling organisations to store, access, and analyse large amounts of data in a consistent and
organised way.
16
Paper-2 Option A Databases
A.2.3 SECURITY
A database management system (DBMS) can be used to promote data security in several ways. Here
are some examples:
Authentication and Access Control: A DBMS can provide authentication mechanisms to verify the
identity of users who access the system. It can also provide access control mechanisms to restrict access
to data and functions based on the user's role, privilege level, or other criteria. This helps to prevent
unauthorised access to sensitive data and functions.
● Encryption: A DBMS can support encryption mechanisms to protect data in transit and at rest.
Encryption can be used to ensure that data is transmitted securely over networks and stored
securely on disk or in memory. This helps to prevent data theft and unauthorised access to data.
● Audit Trail: A DBMS can maintain an audit trail of all activities that occur in the system. The
audit trail can record all changes to data, all login attempts, and other security-related events.
This can help to detect and investigate security breaches or other incidents.
● Backup and Recovery: A DBMS can support backup and recovery mechanisms to protect
against data loss or corruption. Backup mechanisms can be used to create copies of the database
at regular intervals, while recovery mechanisms can be used to restore the database to a
previous state in the event of a system failure, data loss, or other problems.
17
Paper-2 Option A Databases
● Data Masking: A DBMS can support data masking techniques to protect sensitive data by
replacing it with fictitious data. This can be useful in situations where sensitive data is being
used for testing, training or other purposes where the original data is not required.
A DBMS can be used to promote data security by providing authentication and access control
mechanisms, encryption, audit trails, backup and recovery, data masking, and other security features.
By using these features, organizations can help to protect sensitive data, prevent unauthorised access,
and ensure the integrity and availability of their data.
A.2.4 SCHEMA
In database management, a schema refers to the logical structure of a database, which defines the
organization and relationships among the data elements or objects within the database.
A schema can be thought of as a blueprint or plan for the database, which specifies the types
of data that can be stored in the database, the relationships between different types of data,
and the constraints or rules that govern the data.
A database schema typically consists of a set of tables, which represent the different entities or objects
within the database, along with their attributes or fields. The schema defines the structure of each table,
including the data types and constraints for each field, as well as any relationships between tables.
For example, a database schema for a customer database might include tables for customers, orders,
and products, along with fields for each table such as customer name, order date, and product price. The
schema would define the relationships between these tables, such as the fact that each order is
associated with a particular customer and product.
A schema is an important concept in database management, as it provides a logical framework for
organizing and managing data within a database. By defining the schema of a database, organisations
18
Paper-2 Option A Databases
can ensure that the data is structured and organised in a way that supports their business needs and
objectives.
Example: Let us suppose we have three tables Employee, Department and Project. So, we can
represent the schema of these three tables using the schema diagram as follows. In this schema
diagram, Employee and Department are related and the Employee and Project table are related.
There are three levels of the schema. The three levels of the database schema are defined according to
the three levels of data abstraction.
External/View Schema
Conceptual/ Logical Schema
Internal/Physical Schema
19
Paper-2
Paper Option A Databases
The internal schema defines the physical storage structure of the database. The internal schema is a
very low-level
level representation of the entire database. It contains multiple occurrences of multiple types
of internal record. In the ANSI term, it is also called “stored record’.
20
Paper-2 Option A Databases
The conceptual schema describes the Database structure of the whole database for the community of
users. This schema hides information about the physical storage structures and focuses on describing
data types, entities, relationships, etc.
This logical level comes between the user level and physical storage view. However, there is only
single conceptual view of a single database.
View/External Schema(Or)Level
An external schema describes the part of the database which specific user is interested in. It hides the
unrelated details of the database from the user. There may be “n” number of external views for each
database.Each external view is defined using an external schema, which consists of definitions of
various types of external record of that specific view.
An external view is just the content of the database as it is seen by some specific particular user. For
example, a user from the sales department will see only sales related data.
An external level is only related to the data which is viewed by specific end users.
This level includes some external schemas.
External schema level is nearest to the user
The external schema describes the segment of the database which is needed for a certain user
group and hides the remaining details from the database from the specific user group
21
Paper-2 Option A Databases
as a reference source for database administrators, developers, and users, and it provides a standardised
way to document the structure and contents of a database.
The nature of the data dictionary can vary depending on the specific database management system
being used, but it typically includes the following types of information:
● Data Element Descriptions: A data dictionary typically includes a description of each data
element or attribute used in the database, along with information such as the data type, length,
and format of the element.
● Table and Relationship Descriptions: A data dictionary may include descriptions of the tables
in the database, as well as the relationships between the tables. This information can help users
understand the structure of the database and the way data is organised within it.
● Business Rules and Constraints: A data dictionary may also include information about the
business rules and constraints that apply to the data in the database. This can include
information such as data validation rules, default values, and other constraints.
● Data Access Permissions: A data dictionary may also include information about the access
permissions that are required to view or modify data in the database. This can help to ensure
that data is accessed and used appropriately by authorized users.
● Database Management Information: A data dictionary may also include information about
the database management system itself, such as the version of the software being used, the
server configuration, and other technical details.
A data dictionary is a collection of metadata that provides a standardised way to document the structure
and contents of a database. It typically includes information about data elements, tables and
relationships, business rules and constraints, data access permissions, and other technical details related
22
Paper-2 Option A Databases
to the database management system. By providing a centralised source of information about the
database, the data dictionary helps to ensure that data is managed effectively and used appropriately by
authorised users.
A.2.7 DATA DEFINITION LANGUAGE
A data definition language (DDL) is a set of commands or statements used to define and manipulate the
structure of a database. A DDL is used to create and modify tables, indexes, constraints, and other
database objects, and to specify the relationships between these objects. The importance of a DDL in
implementing a data model is as follows:
● Creating Tables and Relationships: The primary function of a DDL is to create the tables and
relationships that make up a database. The DDL specifies the structure and attributes of each
table, including the data types of each field, the constraints that apply to the fields, and the
relationships between tables. By using a DDL to define these elements, developers can ensure
that the data model is accurate and consistent.
● Enforcing Data Integrity: A DDL can also be used to specify constraints that ensure the
integrity of the data in the database. For example, a DDL can specify that a certain field must be
unique or that a field cannot contain null values. These constraints help to ensure that the data in
the database is accurate and consistent.
23
Paper-2 Option A Databases
● Facilitating Database Management: A DDL can also be used to modify the structure of a
database as needed. For example, a DDL can be used to add new tables or fields to a database,
or to modify existing fields or relationships. This allows database administrators to manage the
database effectively and make changes as needed to accommodate changing business needs.
● Supporting Data Security: A DDL can also be used to specify access permissions for different
users or groups of users. By using a DDL to define these permissions, developers can ensure
that the data in the database is accessed and used appropriately by authorised users, and that
sensitive data is protected from unauthorised access.
DDL is an essential tool in implementing a data model, as it allows developers to define and manipulate
the structure of the database, enforce data integrity, facilitate database management, and support data
security. By using a DDL effectively, organisations can ensure that their databases are accurate,
consistent, and secure, and that they meet the needs of the business.
● Data Consistency and Accuracy: A well-designed data model ensures data consistency and
accuracy. A data model defines the rules, constraints, and relationships that govern how data is
24
Paper-2 Option A Databases
organised and stored in the database. By ensuring that data is organised consistently and
accurately, a data model reduces the risk of data inconsistencies and errors.
● Efficiency: A data model helps to improve the efficiency of a database by reducing data
redundancy and improving data retrieval speed. A data model helps to identify and eliminate
data redundancy, ensuring that data is stored only once in the database. This reduces storage
requirements and improves data retrieval speed.
● Flexibility: A well-designed data model is flexible and can adapt to changing business needs. A
data model can be updated and modified easily to accommodate new requirements or changing
business needs.
The importance of data modeling in the design of a database cannot be overstated. A well-designed data
model ensures data consistency and accuracy, improves efficiency, flexibility, collaboration, and
maintainability. By creating a clear blueprint of the database structure and relationships, developers can
create a database that is well-organised, efficient, and flexible enough to meet changing business needs
25
Paper-2 Option A Databases
● Table: A table is a collection of related data organised in rows and columns. Tables are used to
store data in a database and are often named based on the type of data they contain.
● Record: A record is a collection of data that represents a single entity in a table. A record is
also known as a row, and it typically contains information about a specific item or object, such
as a customer, order, or product.
● Field: A field is a single piece of data stored in a record. A field is also known as a column, and
it represents a specific attribute or characteristic of the entity represented by the record.
● Primary Key: A primary key is a field or combination of fields in a table that uniquely
identifies each record in the table. A primary key is used to enforce data integrity and ensure
that no two records in the table are identical.
● Secondary Key: A secondary key is a field or combination of fields in a table that is not the
primary key but can be used to access and query data in the table.
26
Paper-2
Paper Option A Databases
● Foreign Key: A foreign key is a field in a table that refers to the primary key of another table.
A foreign key is used to create a relationship between two tables and ensure data integrity
across the tables.
● Alternate Key
The candidate key other than the primary key is called an alternate key.
● A super key:
Super key is a group of single or multiple keys that identifies rows in a table. It supports NULL
values.
● Unique key:
Unique key in SQL is the set of fields or columns of a table that helps us uniquely identify
records. The unique key guarantees the uniqueness of the columns in the database. It is similar
to the primary key but can accept a null value.
● Candidate Key: A candidate key is a field or combination of fields in a table that could be used
as the primary key but is not currently used for that purpose. A candidate key is used to ensure
that no two records in the table are identical.
27
Paper-2
Paper Option A Databases
28
Paper-2
Paper Option A Databases
Suppose you have two tables, a "Customers" table and an "Orders" table. The "Customers" table
contains information about each customer, such as their name and address, while the "Orders" table
contains information about each order, such as the order number and the customer who placed the
order. Both tables have a common field, such as a customer ID.
To perform an inner join between these two tables, you would specify the customer
cus ID field as the
common field. The inner join would then return only the rows from each table where there is a
matching customer ID, and exclude any rows where there is no matching customer ID.
29
Paper-2 Option A Databases
For example, suppose the "Customers" table has a row with a customer ID of 123 and a name of "John
Smith", and the "Orders" table has a row with an order number of 456 and a customer ID of 123. When
you perform an inner join between these tables, the result set would contain only the row with customer
ID 123, and exclude any other rows where there is no matching customer ID.
In summary, an inner join is a type of join operation that combines data from two or more tables based
on a common field, returning only the rows that have matching values in the specified field. Inner joins
are commonly used in database management to combine data from multiple tables into a single result
set for data analysis or reporting.
An entity is a person, place, thing, or event that is relevant to the database, and is represented by a
rectangle on the diagram.
30
Paper-2
Paper Option A Databases
Types of attribute
Simple Attributes:
Simple attributes are those attributes which cannot be divided further.
Example:
Composite Attributes-
Composite attributes are those attributes which are composed of many other simple attributes.
attributes
31
Paper-2
Paper Option A Databases
Derived Attributes-
Derived attributes are those attributes which can be derived from other attribute(s).
32
Paper-2
Paper Option A Databases
Key attributes
Key attributes are those attributes which can identify an entity uniquely in an entity set.
RELATIONSHIP
A relationship is a connection between entities, and is represented by a line that connects the related
entities.
Key attributes are indicated by underlining the attribute label. For our computer company, each
employee is given an ID number for unique identification.
Participation is a closely related topic. An entity is said to have total participation in a relationship if
every instance of the entity must be matched with instances of the other entity in the relationship. Here
is an example - note that this is a second relationship between employee and factory:
factory
33
Paper-2 Option A Databases
Putting it together
Below is a diagram incorporating the examples above, with some additional attributes to fill out the
entities:
ERDs are used to model complex databases, allowing developers to visualise the relationships between
entities and to identify any potential issues or inconsistencies in the design. They are often used in
conjunction with other tools, such as data flow diagrams and data dictionaries, to ensure that the
database is well-designed and meets the requirements of the stakeholders. ERDs can also be used to
communicate the design of the database to non-technical stakeholders, such as business analysts and
project managers, in a clear and understandable way.
34
Paper-2 Option A Databases
:
A.2.11 | ISSUES WITH REDUNDANT DATA
Redundant data refers to data that is unnecessarily duplicated or repeated in a database. Redundant data
can cause a number of issues, including:
● Data Inconsistency: When data is stored redundantly, it is possible for different copies of the
same data to become inconsistent.
● Data Integrity: Redundant data can also compromise data integrity by making it more difficult
to maintain the accuracy and completeness of the data. When data is stored redundantly, it is
more difficult to ensure that all copies of the data are updated consistently and accurately.
● Storage Costs: Redundant data can also be costly in terms of storage space. When data is
duplicated unnecessarily, it takes up more space in the database, which can increase storage
costs and reduce system performance.
● Maintenance Costs: Redundant data can also increase the cost of maintaining and updating the
database. When data is stored redundantly, it requires additional effort to keep all copies of the
data up to date and accurate.
● Security Risks: Redundant data can also pose security risks by increasing the number of
potential attack points for malicious actors. If redundant data is not properly secured, it can be
more easily accessed and manipulated by unauthorised users.
Redundant data can cause a number of issues for a database, including data inconsistency,
compromised data integrity, increased storage and maintenance costs, and security risks. By
eliminating or minimising redundant data in a database, organisations can improve the accuracy and
consistency of their data, reduce storage and maintenance costs, and enhance data security.
35
Paper-2 Option A Databases
This ensures that the relationships between tables in a database are maintained, ensuring data accuracy
and consistency, data integrity, improved database performance, and enhanced data security. By
ensuring that data is accurate, consistent, and secure, referential integrity helps organisations to make
better decisions and operate more effectively.
A 2.13 NORMALISATION
The normalisation process is used to organise data in a database into tables and establish relationships
between them. The process involves several steps, each of which is designed to remove data
redundancies and dependencies. The three most commonly used normal forms are 1st Normal Form
(1NF), 2nd Normal Form (2NF), and 3rd Normal Form (3NF). Here are the differences between each
of these normal forms:
● 1st Normal Form (1NF): In 1NF, each table in a database contains only atomic values,
meaning that each column contains only a single value. This means that data is not stored in a
repeating group or array format, and each table has a primary key that uniquely identifies each
row.
○ For example, let’s say we have a table named “Students” that stores information about
students in a school. A table that is not in 1NF might look like this:
In this table, the Subject column contains multiple values separated by commas, which
violates the rule of atomic values. This table is not in 1NF. To bring this table to 1NF, we
would need to split the Subject column into multiple columns, one for each subject, and
repeat the student information for each subject taken.
36
Paper-2 Option A Databases
This table is now in 1NF, since all the data is atomic, each cell contains only one value, and
there are no repeating groups of data.
1NF is the starting point for normalization, and to ensure the data integrity and consistency
it’s necessary to move to next normalization forms.
● 2nd Normal Form (2NF): In 2NF, the table must be in 1NF and each non-key column must be
functionally dependent on the entire primary key. This means that each non-key column must
be uniquely determined by the primary key, and cannot be determined by a subset of the
primary key.
For example, let’s say we have a table named “Orders” that stores information about customer
orders. A table that is not in 2NF might look like this:
To bring this table to 2NF, we need to separate the table into two separate tables: one for the
Orders and one for the Products.
37
Paper-2 Option A Databases
Now, the Price column is dependent on the primary key of the Products table (Product) and the
Orders table has no partial dependencies. This design is now in 2NF.
2NF eliminates partial dependencies and improves the data integrity by reducing the data
anomalies. However, it’s not enough to ensure the data consistency and to avoid data anomalies,
so it’s necessary to move to the next normalization forms.
38
Paper-2 Option A Databases
In this table, the Manager column depends on the Department column, and neither of them
depend on the primary key (EmployeeID). This table is not in 3NF because of the transitive
dependency between the Manager column and the Department column.
To bring this table to 3NF, we need to separate the table into two separate tables: one for the
Employees and one for the Departments.
Now, the Manager column is dependent on the primary key of the Departments table
(Department) and the Employees table has no transitive dependencies. This design is now in
3NF.
39
Paper-2 Option A Databases
3NF eliminates transitive dependencies and improves the data integrity and consistency by
reducing the data anomalies. However, it’s still not enough to ensure the data consistency and to
avoid data anomalies, so it’s necessary to move to the next normalization forms like Boyce-
Codd Normal Form (BCNF) or Fourth Normal Form (4NF) in some cases.
● Boyce-Codd Normal Form (BCNF): A relation is in BCNF if and only if for every one of its
non-trivial functional dependencies X → Y, X is a superkey.
● Fourth Normal Form (4NF): A table is in 4NF if it is in BCNF and it has no multi-valued
dependencies.
● Fifth Normal Form (5NF): A relation is in 5NF if every non-trivial join dependency in R is
implied by the candidate keys of R.
To summarise, 1NF requires that each table contain only atomic values, 2NF requires that each
non-key column be functionally dependent on the entire primary key, and 3NF requires that all
non-key columns be independent of each other. These normal forms are used to ensure that the
data in a database is organised efficiently, and is free from data redundancies and dependencies.
40
Paper-2 Option A Databases
● Increased Scalability: A normalised database is highly scalable, meaning that it can be easily
expanded or modified to accommodate new data or changing business needs. This is because
the database is organised into tables, which can be modified or added as needed without
affecting the rest of the database.
● Improved Query Performance: A normalised database often has better query performance
because data is organised into smaller, more manageable tables. This allows queries to be
processed more quickly and efficiently, resulting in faster data retrieval times.
● Simplified Maintenance: A normalised database is easier to maintain because data is organised
into tables, making it easier to identify and fix errors or inconsistencies in the data. This helps to
reduce the cost and effort required to maintain the database over time.
A normalised database is structured in accordance with the principles of database normalisation, with
the aim of reducing data redundancy and ensuring data integrity. A normalised database is characterised
by minimal data redundancy, consistent data, reduced update anomalies, increased scalability,
improved query performance, and simplified maintenance.
41
Paper-2
Paper Option A Databases
The list below shows some data types with example data formats.
Text: Two options within the Text data type are short text and long text. Short text is used for under
256 characters to be entered, as standard most databases as set to short text, and you would need to
specify long text at the set up stage if you want to change tthis.
Numbers: Numbers can normally be formatted as integers, decimal, scientific.
Boolean: Boolean fields are used when you want to enforce one of two options for example YES or
NO, ON or OFF, M or F, TRUE or FALSE, 1 or 0. Some database software may only allow 1 or 0 as
a
options in the boolean datatype selection.
Date/Time: Data and time are often combined, and after selecting this as a data type you select the
format. Time options may be 12 or 24 hour formats and then the format such as hh/mm/ss. Date option
normally include
clude the structure of the date such as DD/MM/YYYY.
42
Paper-2 Option A Databases
Currency: Currency datatype will allow you to choose the currency used for example $ or £, it will
also allow you to specify the number of decimal places.
Object: An object would normally be something that you cannot enter via the keyboard such as music
or a picture, but you could also have items such as hyperlinks as objects.
A.2.16 Construct AN entity-relationship diagram (ERD) for a given scenario.
SCENARIO 1:
Marble Reading Book Stores (MRBS) is a chain of bookstores based in London. The stores want to
keep information about the books they sell the authors of the books and the publishers they work with.
The assumptions made when the database was created were:
o a publisher can publish books from one or more authors
o an author can write one or more books.
Three of the tables in the MRBS database are shown below:
43
Paper-2 Option A Databases
SCENARIO 2:
44
Paper-2 Option A Databases
SCENARIO 3:
45
Paper-2 Option A Databases
A.2.17 Construct a relational database to 3NF using objects such as tables, queries, forms,
reports and macros.
EXAMPLE 1:
46
Paper-2
Paper Option A Databases
EXAMPLE 2:
47
Paper-2 Option A Databases
48
Paper-2 Option A Databases
A.2.18 | QUERIES
A query is a request for data from a database. By executing a query, a user can retrieve and manipulate
data stored in the database. A query can also be used to provide a view of a database, allowing users to
see the data in a specific format that is customised to their needs. Queries can provide a view of a
database in some of the following ways:
● Selecting Fields: When creating a query, the user can select the fields they want to view from
the database. This allows them to focus on specific information that is relevant to their needs.
For example, a user might create a query that selects only the customer name, order number,
and date for all orders placed in the last month.
SELECT custome_name, order_number, date_ordered FROM orders
WHERE order_date >= '2024-02-01' AND order_date < '2024-03-01'
● Filtering Data: Queries can also be used to filter data based on specific criteria. This allows the
user to view only the data that meets their specific needs.
For example, a user might create a query that only shows orders from a specific region or orders
that contain a certain product.
SELECT * FROM orders
WHERE order_region =’ Northwest Alabama'
● Sorting Data: Queries can also be used to sort data in a specific way. This allows the user to
view the data in a way that makes sense for their needs.
For example, a user might create a query that sorts orders by order date, so that the most recent
orders appear at the top. DESC denotes Descending. ASC denotes Ascending.
SELECT * FROM orders
ORDER BY order_date DESC
● Grouping Data: Queries can also be used to group data together based on specific criteria. This
allows the user to view data in a summarised format.
For example, a user might create a query that groups orders by region or by product category.
SELECT * FROM orders
GROUP BY product_category
49
Paper-2 Option A Databases
● Calculating Data: Queries can also be used to calculate data based on specific criteria. This
allows the user to view the data in a way that is useful for their needs.
For example, a user might create a query that calculates the average order size or total sales for
a specific period.
COMPLEX QUERIES
In contrast, a complex query is a more sophisticated request for data from a database, often involving
multiple tables and complex operations. A complex query can be used to retrieve data that meets
specific criteria or to perform advanced calculations or data manipulations.
50
Paper-2 Option A Databases
involve less data and processing. especially if they involve large amounts of data or
complex calculations.
Ease of Use: Simple queries are generally easier Ease of Use: Complex queries may require more
to create and understand than complex queries. advanced technical skills and knowledge
Simple queries can often be created using simple
query languages(SQL) or graphical user
interfaces(GUI) technical skills and knowledge
● Graphical User Interfaces (GUIs): Many database management systems (DBMS) provide
graphical user interfaces (GUIs) that allow users to create queries using a visual interface. Users
can select tables and fields, add filters and sorting criteria, and build complex queries using
drag-and-drop functionality.
● Query Languages: Query languages such as SQL (Structured Query Language) and LINQ
(Language-Integrated Query) can be used to construct queries. These languages provide a
syntax for creating queries that can be executed on a database. SQL is a standard language used
for creating and managing relational databases, while LINQ is a .NET Framework component
used to query collections and databases.
● Stored Procedures: A stored procedure is a set of precompiled SQL statements that can be
executed on a database. Stored procedures can be created to perform specific tasks or to retrieve
data that meets specific criteria. They can be called from applications or other stored procedures
to retrieve data from the database.
● Data Access Layers: Data access layers provide a way to abstract the database from the
application code. They provide a set of methods and functions that can be used to retrieve data
from the database. The data access layer can be used to create queries, and the results can be
returned to the application code for further processing.
51
Paper-2 Option A Databases
● Object-Relational Mapping (ORM): ORM tools provide a way to map database tables to
object-oriented code. The ORM tool can be used to create queries and retrieve data from the
database. The results can be returned as objects that can be used by the application code.
● Web-Based Interfaces: Web-based interfaces can be used to create and execute queries from a
web browser. These interfaces can provide a simple way to access the database from anywhere
with an internet connection.
There are several methods that can be used to construct a query, including graphical user interfaces,
query languages, stored procedures, data access layers, object-relational mapping tools, and web-based
interfaces. The choice of method depends on the specific requirements of the user and the database
management system being used.
52
Paper-2 Option A Databases
A database administrator (DBA) is responsible for the design, implementation, maintenance, and
management of an organisation's databases. The specific responsibilities of a DBA may vary depending
on the size and complexity of the organisation, but some common responsibilities include:
● Design and implementation: DBAs are responsible for designing and implementing the
database architecture, including the physical storage and organisation of the data, the logical
relationships between the data entities, and the security and access controls.
● Maintenance and performance tuning: DBAs are responsible for maintaining the databases
and ensuring their performance and availability. This includes monitoring performance metrics,
53
Paper-2 Option A Databases
tuning the database for optimal performance, and performing regular backups and disaster
recovery operations.
Maintenance and Data security
Design and
implementation performance tuning
● Data security: DBAs are responsible for ensuring the security and privacy of the data stored in
the databases, including the implementation of access controls, data encryption, and other
security measures.
● User management: DBAs are responsible for managing user accounts and permissions,
ensuring that the appropriate access controls are in place to ensure the security and privacy of
the data.
● Data modelling and architecture: DBAs are responsible for defining the data models and
architecture that support the organisation's data requirements, ensuring that the data is organised
in a way that supports the organisation's goals and objectives.
● Monitoring and troubleshooting: DBAs are responsible for monitoring the databases and
troubleshooting any issues that arise, including performance bottlenecks, data integrity
problems, and security incidents.
● Training and support: DBAs may also be responsible for providing training and support to
other stakeholders, such as developers and end-users, to help them effectively use the databases
and understand the data stored in the databases.
The role of a DBA is critical to the success of an organisation, as the DBA is responsible for ensuring
the accuracy, security, and performance of the organisation's data. By fulfilling these responsibilities,
DBAs help organisations to make informed decisions and support their goals and objectives.
54
Paper-2 Option A Databases
● Database Administrators: Database administrators (DBAs) are responsible for managing the
database and ensuring its security, availability, and performance. They typically interact with
the database using specialized tools that are designed to manage and monitor databases. These
tools may include command-line interfaces, GUIs, or web-based interfaces that allow DBAs to
perform tasks such as creating backups, managing users and permissions, monitoring
performance, and tuning the database.
● Internal Employees: Internal employees may interact with a database in a variety of ways,
depending on their roles and responsibilities.
For example, sales representatives may use a web-based interface to access customer data and
create new orders, while managers may use reporting tools to generate reports and analyse data.
55
Paper-2 Option A Databases
The interfaces provided to internal employees may be customised to their specific needs, and
may include features such as forms, dashboards, and reports that are tailored to their roles.
● External Customers: External customers may interact with a database using web-based
interfaces or mobile applications. These interfaces may allow customers to view their account
information, place orders, or track shipments. The interfaces provided to external customers are
typically designed to be easy to use and intuitive, with a focus on providing a positive user
experience.
Database administrators, internal employees, and external customers may interact with a database in
different ways, depending on their roles and responsibilities. The interfaces provided to these groups
may also differ, depending on their specific needs and requirements. The key is to provide an interface
that is customised to each group, and that makes it easy to perform the tasks they need to do in an
efficient and user-friendly manner.
● System Log: A system log, also known as a transaction log or audit trail, is a record of all
changes made to a database.
○ It is used to track the history of database transactions, and to provide a way to recover
from errors or failures.
○ The system log records details such as the time and date of the transaction, the user who
made the change, and the type of change that was made.
○ By using a system log, it is possible to undo or redo changes that were made to the
database, which can be useful in recovering from errors or restoring the database to a
previous state.
56
Paper-2
Paper Option A Databases
● Deferred Update:
○ Deferred update is a technique used in database management to improve performance
and reduce the risk of data inconsistencies.
○ In a deferred update system, changes made to a database are not immediately
imme written to
disk, but are instead held in memory until a commit point is reached.
reached
○ Once the commit point is reached, all the changes are written to the database in a single
batch. This can reduce the overhead of writing to the disk for each individual
individua
transaction, and can improve performance.
○ However, it also means that data may not be immediately available for other
transactions, which can lead to concurrency issues.
● Mirroring:
○ Mirroring involves creating a duplicate copy of a database on a separate server.
○ In the event of a failure, the duplicate copy can be used to recover the database.
○ This method can be used to provide high availability and fast recovery times, but it can
be complex to set up and maintain.
It is designed to integrate data from various systems, applications, and databases, and to provide a
single point of access for users. Here's an outline of how integrated database systems function:
57
Paper-2 Option A Databases
● Data Integration: The next step is data integration. Data from different sources is integrated
into a single, unified format. This involves transforming data from its original format into a
common format that can be easily accessed and analysed.
● Data Cleansing: Data cleansing involves identifying and correcting errors, inconsistencies, and
duplicates in the data. This is an important step in ensuring that the data is accurate, complete,
and consistent.
● Data Storage: Once the data has been collected, integrated, and cleansed, it is stored in a
centralised database or data warehouse. This database is optimised for querying and analysis,
and may use specialised storage technologies such as columnar storage or in-memory databases.
● Data Access: The final step is data access. Users can access the data in the integrated database
system using a variety of tools, such as SQL queries, data visualisation tools, or reporting tools.
The system may also provide APIs or web services for programmatic access.
An integrated database system is designed to provide a centralised, unified view of data from multiple
sources. It involves collecting data, integrating it into a common format, cleansing it, storing it in a
centralised database or data warehouse, and providing access to users through a variety of tools and
interfaces. The goal is to provide a single point of access for users and to ensure that the data is
accurate, complete, and consistent.
● Stock Control: Databases are used in stock control systems to manage inventory levels and
track sales. The database contains information about each product, including its SKU,
description, price, and quantity on hand. When a sale is made, the database is updated to reflect
the change in inventory levels. Reports can be generated from the database to help with
forecasting, ordering, and reordering.
● Police Records: Databases are used in police records systems to store and manage information
about crimes, suspects, and victims. The database contains details such as the location and date
of the crime, the type of crime, and any evidence or witness statements. This information can be
used to identify patterns, track suspects, and solve crimes.
58
Paper-2 Option A Databases
● Health Records: Databases are used in healthcare systems to store and manage patient health
records. The database contains information such as the patient's name, age, medical history,
diagnoses, medications, and test results. This information can be used by healthcare providers to
make informed decisions about treatment, monitor patient progress, and provide better care.
● Employee Data: Databases are used in human resources systems to store and manage employee
data. The database contains information such as the employee's name, address, contact
information, job title, salary, and benefits. This information can be used to manage payroll,
track performance, and provide benefits to employees.
Databases are used in many different areas to store and manage data, including stock control, police
records, health records, and employee data. The information stored in these databases can be used for a
variety of purposes, such as tracking inventory, solving crimes, providing healthcare, and managing
human resources.
● Data Encryption: Data encryption is a process of converting data into a coded form to protect
its confidentiality. Encryption can be used to protect data in transit or data at rest.
● Access Controls: Access controls are security measures that restrict access to data based on the
user's identity, role, or permissions. This can include password protection, multi-factor
authentication, and role-based access control.
● Secure Data Storage: Data should be stored in a secure location, such as a server room with
access control and surveillance cameras. In addition, data backups should be stored offsite in a
secure location.
● Regular Security Audits: Regular security audits should be conducted to ensure that data is
protected from unauthorised access, and that all security controls are functioning as intended.
59
Paper-2 Option A Databases
HUMAN METHODS
● Employee Training: Employees should be trained on the importance of data privacy, as well as
the policies and procedures for protecting personal data. Training should include how to handle
personal data securely and how to detect and report any privacy breaches.
● Access Controls: Access controls should also be enforced for human users, including
restricting access to personal data on a need-to-know basis, and providing training on how to
handle sensitive data.
● Background Checks: Employees who have access to personal data should undergo background
checks to ensure that they have a trustworthy background.
● Privacy Policies and Notices: Privacy policies and notices should be created and made
available to all employees, customers, and partners. These should clearly state the organization's
privacy practices and procedures.
Ensuring privacy of personal data from both a computer and human point of view requires a
combination of technical and organizational measures. This includes data encryption, access controls,
secure data storage, regular security audits, employee training, access controls for human users,
background checks, and privacy policies and notices. By implementing these measures, organizations
can ensure the confidentiality, integrity, and availability of personal data.
● Criminal Investigations: Law enforcement agencies may need to interrogate database systems
to gather evidence in criminal investigations. This may involve accessing records of suspects,
victims, or witnesses.
● Medical Emergencies: Medical services may need to interrogate database systems to access
medical records in cases of emergency. This can help medical professionals make informed
decisions about treatment and care.
● Compliance and Regulations: Some industries, such as finance and healthcare, are subject to
strict regulations and compliance requirements. Third parties may need to interrogate database
systems to ensure that organisations are complying with these regulations.
60
Paper-2 Option A Databases
It is important to balance the need for access with privacy and security concerns, and to ensure that
access to personal data is limited to those who have a legitimate need to know.
61