0% found this document useful (0 votes)
20 views

Lesson 19 - Develop Website Backend System

web dev

Uploaded by

Dhoy Navarro
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Lesson 19 - Develop Website Backend System

web dev

Uploaded by

Dhoy Navarro
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

age 1 of 28

Lesson 19 – Develop Website Backend System (Part 3)

Objectives:
1. Define database conceptual model.
2. Identify and normalize attributes and data types.
3. Design data structures.
4. Learn to populate database with test and actual data.

Content:
Database conceptual model is defined
A database model shows the logical structure of a database, including the relationships and constraints
that determine how data can be stored and accessed. Individual database models are designed based on
the rules and concepts of whichever broader data model the designers adopt.

What is a Database Model?

A database model shows the logical structure of a database, including the relationships and constraints
that determine how data can be stored and accessed. Individual database models are designed based on
the rules and concepts of whichever broader data model the designers adopt. Most data models can be
represented by an accompanying database diagram.

Types of database models

There are many kinds of data models. Some of the most common ones include:

 Hierarchical database model


 Relational model
 Network model
 Object-oriented database model
 Entity-relationship model
 Document model
 Entity-attribute-value model
 Star schema
 The object-relational model, which combines the two that make up its name

You may choose to describe a database with any one of these depending on several factors. The biggest
factor is whether the database management system you are using supports a particular model. Most
database management systems are built with a particular data model in mind and require their users to
adopt that model, although some do support multiple models.

In addition, different models apply to different stages of the database design process. High-level
conceptual data models are best for mapping out relationships between data in ways that people
age 2 of 28

perceive that data. Record-based logical models, on the other hand, more closely reflect ways that the
data is stored on the server.

Selecting a data model is also a matter of aligning your priorities for the database with the strengths of a
particular model, whether those priorities include speed, cost reduction, usability, or something else.

Let’s take a closer look at some of the most common database models.

Relational model

The most common model, the relational model sorts data into tables, also known as relations, each of
which consists of columns and rows. Each column lists an attribute of the entity in question, such as
price, zip code, or birth date. Together, the attributes in a relation are called a domain. A particular
attribute or combination of attributes is chosen as a primary key that can be referred to in other tables,
when it’s called a foreign key.

Each row, also called a tuple, includes data about a specific instance of the entity in question, such as a
particular employee.

The model also accounts for the types of relationships between those tables, including one-to-one, one-
to-many, and many-to-many relationships. Here’s an example:

Within the database, tables can be normalized, or brought to comply with normalization rules that make
the database flexible, adaptable, and scalable. When normalized, each piece of data is atomic, or broken
into the smallest useful pieces.

Relational databases are typically written in Structured Query Language (SQL). The model was
introduced by E.F. Codd in 1970.

Hierarchical model

The hierarchical model organizes data into a tree-like structure, where each record has a single parent
or root. Sibling records are sorted in a particular order. That order is used as the physical order for
storing the database. This model is good for describing many real-world relationships.
age 3 of 28

This model was primarily used by IBM’s Information Management Systems in the 60s and 70s, but they
are rarely seen today due to certain operational inefficiencies.

Network model

The network model builds on the hierarchical model by allowing many-to-many relationships between
linked records, implying multiple parent records. Based on mathematical set theory, the model is
constructed with sets of related records. Each set consists of one owner or parent record and one or
more member or child records. A record can be a member or child in multiple sets, allowing this model
to convey complex relationships.

It was most popular in the 70s after it was formally defined by the Conference on Data Systems
Languages (CODASYL).
age 4 of 28

Object-oriented database model

This model defines a database as a collection of objects, or reusable software elements, with associated
features and methods. There are several kinds of object-oriented databases:

A multimedia database

incorporates media, such as images, that could not be stored in a relational database.

A hypertext database

allows any object to link to any other object. It’s useful for organizing lots of disparate data, but it’s not
ideal for numerical analysis.

The object-oriented database model is the best known post-relational database model, since it
incorporates tables, but isn’t limited to tables. Such models are also known as hybrid database models.
age 5 of 28

Object-relational model

This hybrid database model combines the simplicity of the relational model with some of the advanced
functionality of the object-oriented database model. In essence, it allows designers to incorporate
objects into the familiar table structure.

Languages and call interfaces include SQL3, vendor languages, ODBC, JDBC, and proprietary call
interfaces that are extensions of the languages and interfaces used by the relational model.

Entity-relationship model

This model captures the relationships between real-world entities much like the network model, but it
isn’t as directly tied to the physical structure of the database. Instead, it’s often used for designing a
database conceptually.

Here, the people, places, and things about which data points are stored are referred to as entities, each
of which has certain attributes that together make up their domain. The cardinality, or relationships
between entities, are mapped as well.
age 6 of 28

A common form of the ER diagram is the star schema, in which a central fact table connects to multiple
dimensional tables.

Other database models

A variety of other database models have been or are still used today.

Inverted file model

A database built with the inverted file structure is designed to facilitate fast full text searches. In this
model, data content is indexed as a series of keys in a lookup table, with the values pointing to the
location of the associated files. This structure can provide nearly instantaneous reporting in big data and
analytics, for instance.

This model has been used by the ADABAS database management system of Software AG since 1970, and
it is still supported today.
age 7 of 28

Flat model

The flat model is the earliest, simplest data model. It simply lists all the data in a single table, consisting
of columns and rows. In order to access or manipulate the data, the computer has to read the entire flat
file into memory, which makes this model inefficient for all but the smallest data sets.

Multidimensional model

This is a variation of the relational model designed to facilitate improved analytical processing. While the
relational model is optimized for online transaction processing (OLTP), this model is designed for online
analytical processing (OLAP).

Each cell in a dimensional database contains data about the dimensions tracked by the database.
Visually, it’s like a collection of cubes, rather than two-dimensional tables.

Semistructured model

In this model, the structural data usually contained in the database schema is embedded with the data
itself. Here the distinction between data and schema is vague at best. This model is useful for describing
systems, such as certain Web-based data sources, which we treat as databases but cannot constrain
with a schema. It’s also useful for describing interactions between databases that don’t adhere to the
same schema.

Context model

This model can incorporate elements from other database models as needed. It cobbles together
elements from object-oriented, Semistructured, and network models.

Associative model

This model divides all the data points based on whether they describe an entity or an association. In this
model, an entity is anything that exists independently, whereas an association is something that only
exists in relation to something else.

The associative model structures the data into two sets:

 A set of items, each with a unique identifier, a name, and a type


 A set of links, each with a unique identifier and the unique identifiers of a source, verb, and target.
The stored fact has to do with the source, and each of the three identifiers may refer either to a link
or an item.

Other, less common database models include:

 Semantic model, which includes information about how the stored data relates to the real world
 XML database, which allows data to be specified and even stored in XML format
 Named graph
 Triplestore
age 8 of 28

NoSQL database models

In addition to the object database model, other non-SQL models have emerged in contrast to the
relational model:

The

graph database model, which is even more flexible than a network model, allowing any node to connect
with any other.

The

multivalue model, which breaks from the relational model by allowing attributes to contain a list of data
rather than a single data point.

The

document model, which is designed for storing and managing documents or semi-structured data,
rather than atomic data.

Databases on the Web

Most websites rely on some kind of database to organize and present data to users. Whenever someone
uses the search functions on these sites, their search terms are converted into queries for a database
server to process. Typically, middleware connects the web server with the database.

Attributes and data types are identified

A data type is an attribute that specifies the type of data that the object can hold: integer data,
character data, monetary data, date and time data, binary strings, and so on.

What are Attributes?

 Attributes are qualities or characteristics that describe an object, individual, or phenomenon.


 Attributes can be categorical, representing distinct categories or classes, such as colors, types, or
labels.
 Some attributes are quantitative, taking on numerical values that can be measured or counted,
such as height, weight, or temperature.
 Categorical attributes can be further classified as nominal (no inherent order) or ordinal
(possessing a meaningful order).
 In data analysis, attributes serve as the variables of interest, and understanding their nature is
crucial for selecting appropriate statistical methods and drawing meaningful conclusions from the
data.
age 9 of 28

SQL Data Types for MySQL, SQL Server, and MS Access


SQL Data Types

Each column in a database table is required to have a name and a data type.

An SQL developer must decide what type of data that will be stored inside each
column when creating a table. The data type is a guideline for SQL to
understand what type of data is expected inside of each column, and it also
identifies how SQL will interact with the stored data.

SQL Data Types

Each column in a database table is required to have a name and a data type.

An SQL developer must decide what type of data that will be stored inside each
column when creating a table. The data type is a guideline for SQL to
understand what type of data is expected inside of each column, and it also
identifies how SQL will interact with the stored data.

MySQL Data Types (Version 8.0)

In MySQL there are three main data types: string, numeric, and date and time.

String Data Types

Data type Description

CHAR(size) A FIXED length string (can contain letters, numbers,


and special characters). The size parameter specifies the
column length in characters - can be from 0 to 255.
Default is 1

VARCHAR(size) A VARIABLE length string (can contain letters, numbers,


and special characters). The size parameter specifies the
maximum string length in characters - can be from 0 to
65535

BINARY(size) Equal to CHAR(), but stores binary byte strings.


The size parameter specifies the column length in bytes.
Default is 1

VARBINARY(size) Equal to VARCHAR(), but stores binary byte strings.


age 10 of 28

The size parameter specifies the maximum column


length in bytes.

TINYBLOB For BLOBs (Binary Large Objects). Max length: 255


bytes

TINYTEXT Holds a string with a maximum length of 255 characters

TEXT(size) Holds a string with a maximum length of 65,535 bytes

BLOB(size) For BLOBs (Binary Large Objects). Holds up to 65,535


bytes of data

MEDIUMTEXT Holds a string with a maximum length of 16,777,215


characters

MEDIUMBLOB For BLOBs (Binary Large Objects). Holds up to


16,777,215 bytes of data

LONGTEXT Holds a string with a maximum length of 4,294,967,295


characters

LONGBLOB For BLOBs (Binary Large Objects). Holds up to


4,294,967,295 bytes of data

ENUM(val1, val2, A string object that can have only one value, chosen
val3, ...) from a list of possible values. You can list up to 65535
values in an ENUM list. If a value is inserted that is not
in the list, a blank value will be inserted. The values are
sorted in the order you enter them

SET(val1, val2, A string object that can have 0 or more values, chosen
val3, ...) from a list of possible values. You can list up to 64
values in a SET list

Numeric Data Types

Data type Description

BIT(size) A bit-value type. The number of bits per value is


specified in size. The size parameter can hold a value
from 1 to 64. The default value for size is 1.

TINYINT(size) A very small integer. Signed range is from -128 to 127.


Unsigned range is from 0 to 255. The size parameter
specifies the maximum display width (which is 255)
age 11 of 28

BOOL Zero is considered as false, nonzero values are


considered as true.

BOOLEAN Equal to BOOL

SMALLINT(size) A small integer. Signed range is from -32768 to 32767.


Unsigned range is from 0 to 65535. The size parameter
specifies the maximum display width (which is 255)

MEDIUMINT(size) A medium integer. Signed range is from -8388608 to


8388607. Unsigned range is from 0 to 16777215.
The size parameter specifies the maximum display
width (which is 255)

INT(size) A medium integer. Signed range is from -2147483648


to 2147483647. Unsigned range is from 0 to
4294967295. The size parameter specifies the
maximum display width (which is 255)

INTEGER(size) Equal to INT(size)

BIGINT(size) A large integer. Signed range is from -


9223372036854775808 to 9223372036854775807.
Unsigned range is from 0 to 18446744073709551615.
The size parameter specifies the maximum display
width (which is 255)

FLOAT(size, d) A floating point number. The total number of digits is


specified in size. The number of digits after the decimal
point is specified in the d parameter. This syntax is
deprecated in MySQL 8.0.17, and it will be removed in
future MySQL versions

FLOAT(p) A floating point number. MySQL uses the p value to


determine whether to use FLOAT or DOUBLE for the
resulting data type. If p is from 0 to 24, the data type
becomes FLOAT(). If p is from 25 to 53, the data type
becomes DOUBLE()

DOUBLE(size, d) A normal-size floating point number. The total number


of digits is specified in size. The number of digits after
the decimal point is specified in the d parameter

DOUBLE
PRECISION(size, d)
age 12 of 28

DECIMAL(size, d) An exact fixed-point number. The total number of


digits is specified in size. The number of digits after the
decimal point is specified in the d parameter. The
maximum number for size is 65. The maximum
number for d is 30. The default value for size is 10.
The default value for d is 0.

DEC(size, d) Equal to DECIMAL(size,d)

Note: All the numeric data types may have an extra option: UNSIGNED or
ZEROFILL. If you add the UNSIGNED option, MySQL disallows negative values
for the column. If you add the ZEROFILL option, MySQL automatically also
adds the UNSIGNED attribute to the column.

Date and Time Data Types

Data type Description

DATE A date. Format: YYYY-MM-DD. The supported range is


from '1000-01-01' to '9999-12-31'

DATETIME(fsp) A date and time combination. Format: YYYY-MM-DD


hh:mm:ss. The supported range is from '1000-01-01
00:00:00' to '9999-12-31 23:59:59'. Adding DEFAULT
and ON UPDATE in the column definition to get
automatic initialization and updating to the current
date and time

TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the


number of seconds since the Unix epoch ('1970-01-01
00:00:00' UTC). Format: YYYY-MM-DD hh:mm:ss. The
supported range is from '1970-01-01 00:00:01' UTC to
'2038-01-09 03:14:07' UTC. Automatic initialization
and updating to the current date and time can be
specified using DEFAULT CURRENT_TIMESTAMP and
ON UPDATE CURRENT_TIMESTAMP in the column
definition

TIME(fsp) A time. Format: hh:mm:ss. The supported range is


from '-838:59:59' to '838:59:59'

YEAR A year in four-digit format. Values allowed in four-digit


format: 1901 to 2155, and 0000.
MySQL 8.0 does not support year in two-digit format.
age 13 of 28

SQL Server Data Types


String Data Types

Data type Description Max size Storage

char(n) Fixed width character 8,000 characters Defined width


string

varchar(n) Variable width character 8,000 characters 2 bytes +


string number of
chars

varchar(max) Variable width character 1,073,741,824 2 bytes +


string characters number of
chars

text Variable width character 2GB of text data 4 bytes +


string number of
chars

nchar Fixed width Unicode 4,000 characters Defined width


string x2

nvarchar Variable width Unicode 4,000 characters


string

nvarchar(max) Variable width Unicode 536,870,912


string characters

ntext Variable width Unicode 2GB of text data


string

binary(n) Fixed width binary string 8,000 bytes

varbinary Variable width binary 8,000 bytes


string

varbinary(max) Variable width binary 2GB


string

image Variable width binary 2GB


string

Numeric Data Types

Data type Description Storage


age 14 of 28

bit Integer that can be 0, 1, or NULL

tinyint Allows whole numbers from 0 to 255 1 byte

smallint Allows whole numbers between -32,768 and 2 bytes


32,767

int Allows whole numbers between - 4 bytes


2,147,483,648 and 2,147,483,647

bigint Allows whole numbers between - 8 bytes


9,223,372,036,854,775,808 and
9,223,372,036,854,775,807

decimal(p,s) Fixed precision and scale numbers. 5-17 bytes


Allows numbers from -10^38 +1 to 10^38 –1.
The p parameter indicates the maximum total
number of digits that can be stored (both to
the left and to the right of the decimal point).
p must be a value from 1 to 38. Default is 18.
The s parameter indicates the maximum
number of digits stored to the right of the
decimal point. s must be a value from 0 to p.
Default value is 0

numeric(p,s) Fixed precision and scale numbers. 5-17 bytes


Allows numbers from -10^38 +1 to 10^38 –1.
The p parameter indicates the maximum total
number of digits that can be stored (both to
the left and to the right of the decimal point).
p must be a value from 1 to 38. Default is 18.
The s parameter indicates the maximum
number of digits stored to the right of the
decimal point. s must be a value from 0 to p.
Default value is 0

smallmoney Monetary data from -214,748.3648 to 4 bytes


214,748.3647

money Monetary data from - 8 bytes


922,337,203,685,477.5808 to
922,337,203,685,477.5807

float(n) Floating precision number data from -1.79E + 4 or 8 bytes


308 to 1.79E + 308.
The n parameter indicates whether the field
age 15 of 28

should hold 4 or 8 bytes. float(24) holds a 4-


byte field and float(53) holds an 8-byte field.
Default value of n is 53.

real Floating precision number data from -3.40E + 4 bytes


38 to 3.40E + 38

Date and Time Data Types

Data type Description Storage

datetime From January 1, 1753 to December 31, 9999 with 8 bytes


an accuracy of 3.33 milliseconds

datetime2 From January 1, 0001 to December 31, 9999 with 6-8 bytes
an accuracy of 100 nanoseconds

smalldatetime From January 1, 1900 to June 6, 2079 with an 4 bytes


accuracy of 1 minute

date Store a date only. From January 1, 0001 to 3 bytes


December 31, 9999

time Store a time only to an accuracy of 100 3-5 bytes


nanoseconds

datetimeoffset The same as datetime2 with the addition of a time 8-10


zone offset bytes

timestamp Stores a unique number that gets updated every


time a row gets created or modified. The
timestamp value is based upon an internal clock
and does not correspond to real time. Each table
may have only one timestamp variable

Other Data Types

Data type Description

sql_variant Stores up to 8,000 bytes of data of various data types, except


text, ntext, and timestamp

uniqueidentifier Stores a globally unique identifier (GUID)

xml Stores XML formatted data. Maximum 2GB


age 16 of 28

cursor Stores a reference to a cursor used for database operations

table Stores a result-set for later processing

MS Access Data Types

Data type Description Storage

Text Use for text or combinations of text and


numbers. 255 characters maximum

Memo Memo is used for larger amounts of text. Stores


up to 65,536 characters. Note: You cannot sort a
memo field. However, they are searchable

Byte Allows whole numbers from 0 to 255 1 byte

Integer Allows whole numbers between -32,768 and 2 bytes


32,767

Long Allows whole numbers between -2,147,483,648 4 bytes


and 2,147,483,647

Single Single precision floating-point. Will handle most 4 bytes


decimals

Double Double precision floating-point. Will handle most 8 bytes


decimals

Currency Use for currency. Holds up to 15 digits of whole 8 bytes


dollars, plus 4 decimal places. Tip: You can
choose which country's currency to use

AutoNumber AutoNumber fields automatically give each 4 bytes


record its own number, usually starting at 1

Date/Time Use for dates and times 8 bytes

Yes/No A logical field can be displayed as Yes/No, 1 bit


True/False, or On/Off. In code, use the
constants True and False (equivalent to -1 and
0). Note: Null values are not allowed in Yes/No
fields

Ole Object Can store pictures, audio, video, or other BLOBs up to


(Binary Large Objects) 1GB
age 17 of 28

Hyperlink Contain links to other files, including web pages

Lookup Wizard Let you type a list of options, which can then be 4 bytes
chosen from a drop-down list

Data Structures are designed

A data structure is a specialized format for organizing, processing, retrieving and storing data. There are
several basic and advanced types of data structures, all designed to arrange data to suit a specific
purpose. Data structures make it easy for users to access and work with the data they need in
appropriate ways.

Data Structure Design

The process of development and organization of data structures that can effectively store, manipulate,
and retrieve data in a computer program or system is termed data structure design. Effective data
management and organization are crucial for performance optimization, enabling efficient algorithms,
and facilitating data manipulation and access.

The specification of the programme (what the programme does) serves as the starting point for the data
structure design approach, which ends with the detailed programme design presented as a pseudo-
code.

Steps for Data Structure Design

1. Creation of diagrammatic representations of input and output data structures that will be used by the
programmer.
2. Creation of a single programme structure diagram with the combination of all data structure
programmes.
3. Determine and record the actions that the programme will take.
4. Connect the programme structure diagram to these specified operations and then put all these
operations in the suitable spot in the programme.
5. In the last step, this programme structure diagram is then transformed into a pseudo-code.

Principles of Data Structure Design

 Efficiency: To make the best use of system resources like time and memory, data structures should
be created. They should carry out tasks quickly and simply, reducing the time and physical space
requirements of routine tasks like insertion, deletion, searching, and retrieval.
 Correctness: The data structure should deliver correct results and serve the desired goal. It should
be able to handle every input and operation without making any unforeseen mistakes or
inconsistencies.
 Encapsulation: Both the data and the operations that can be applied to it should be contained
within data structures. This protects data integrity and hinders unauthorized access by making sure
that the internal representation and alteration of the data are hidden from outside parties.
age 18 of 28

 Abstraction: Data structures ought to offer a distinct and well-defined interface or abstraction that
shields users from implementation-specific details. It makes codebase easier to understand.
 Reusability: To protect users from implementation-specific details, data structures should provide a
unique and clearly defined interface or abstraction. This promotes modularity and makes it simpler
to comprehend and manage the programme.
 Credibility: Data structures should be created to support a variety of use cases and applications.
They ought to be adaptive and versatile, enabling simple extension or alteration without
significantly altering the underlying structure.
 Maintainability: Maintainability should be considered while designing data structures so that the
codebase is simpler to comprehend, alter, and troubleshoot. The maintainability of the data
structures can be significantly improved by employing clear and succinct naming conventions,
adequate documentation, and adherence to coding standards.
 Scalability: Scalable data structures can manage to expand or shift data sizes. The system should be
able to handle increasing workloads without noticeably degrading performance since it should
demonstrate strong performance characteristics even when dealing with enormous datasets.
 Modularity: Modular data structures would enable autonomous component creation and testing.
This makes code organization easier, encourages code reuse, and makes debugging and
troubleshooting procedures simpler.
 Consistency: The consistent architecture of data structures guarantees that related actions or
functionality operate predictably and consistently. It makes data structure less complex and more
usable.

Best Practices for Creating Efficient and Scalable Data Structures

 Choosing the Right Data Structure: The right data structure must be chosen for an application to be
effective and scalable. Consider your data’s qualities and select a structure that offers effective
operations for the necessary use cases. Examples of common data structures are graphs, hash
tables, trees, arrays, linked tables, etc.
 Understanding the Requirement: Be sure to fully comprehend the needs of your application before
building a data structure. Optimize the data structure based on the activities that must be carried
out frequently.
 Optimization of Access Pattern: Before creating a data structure, make sure you thoroughly
understand the requirements of your application. Optimize the data structure based on the
frequent actions that must be taken.
 Minimization of Memory Footprint: Effective data structures make good use of memory. Reduce
unused memory usage by selecting the right data types and storage-optimizing techniques. Think
about the trade-offs between time complexity and memory utilization.
 Consider Caching: Performance can be greatly enhanced by using caching techniques. Create data
structures that benefit from caching techniques, such as by implementing LFU (Least Frequently
Used) or LRU (Least Recently Used) caching algorithms.
 Minimized unnecessary copying: Reduce the amount of needless data copying to save overhead.
Use pointers or references to share data between data structures whenever possible to avoid
duplicating data.
 Maintaining a balance between the elements like deletions, insertions, and lookups: Choose an
appropriate balance between effective deletions, insertions, and lookups depending on the criteria
of the application. Some data structures are more advantageous than others when it comes to
age 19 of 28

certain processes. For instance, balanced search trees like AVL trees offer quick lookups but take
longer to insert data than hash tables do.
 Analyze Space and Time Complexity: Select an appropriate ratio of effective insertions, deletions,
and lookups based on the specifications of your application. Some data structures perform better
than others when it comes to certain processes. For example, hash tables insert data more quickly
than balanced search trees, such as AVL trees, which provide quick lookups.
 Modularize the data structure: Create modular, reusable data structures for your applications.
Make construction elements that can be joined to create more intricate buildings. This strategy
encourages the maintainability of the code, minimizes duplication, and permits scalability.
 Use pre-existing libraries: Use pre-existing libraries or frameworks that offer effective and scalable
data structures whenever possible. These libraries are often performance-tested and enhanced.
 Test and Benchmark: Benchmark the performance of your data structures after thoroughly testing
them with representative data sets.

Importance of Data Structure

Most computer programming languages’ standard base data types, such as integers or floating-point
numbers, are typically insufficient to convey the logical intent for data processing and application.
However, in order to make processing easier, programmes that consume, manipulate, and output
information need to be aware of how data should be organized. Data structures enable the efficient
usage, persistence, and sharing of data by logically combining the data parts. They offer a formal model
that outlines the arrangement of the data items.

Data structures serve as the foundation for more complex applications. In order to create them, data
components are combined into logical units that reflect abstract data types relevant to the algorithm or
application. A “customer name” is an illustration of an abstract data type. It is made up of the character
strings for the “first name,” “middle name,” and “last name.”

Database is populated with test or actual data.

Databases are a critical component of most software systems and applications. As a result, thoroughly
testing and validating databases is essential to ensure systems function properly.

Database Testing

What is Database Testing?

Database testing refers to the process of checking a database system to verify it meets requirements and
performs as expected. The main goals of database testing include:

 Validating Data Integrity: Confirming the accuracy and consistency of data stored in the database.
This includes checking for any corrupted, duplicate, or missing data.
 Verifying Functionality: Testing common database operations like inserts, updates, deletes, and
queries to ensure they work as intended.
 Assessing Performance: Load testing and benchmarking databases under expected workloads in
terms of response times, throughput, resource utilization, and scalability.
age 20 of 28

 Testing Backup and Recovery: Validating backup plans and disaster recovery procedures
successfully restore database contents and functionality.
 Checking Security: Testing user authentication, access controls, encryption, and other security
measures.
 Confirming Compliance: Ensuring the database meets regulatory compliance standards if required.
This is common in financial services, healthcare, etc.

Database testing is an important step in minimizing data loss and corruption, avoiding system failures,
and reducing cybersecurity risks that could occur in production if databases have undiscovered flaws.

When Should Database Testing Be Done?

Comprehensive database testing requires evaluating databases at multiple points:

 Unit Testing: Developers should create low-level test cases that target individual database
components like triggers, procedures, queries, etc. This is done during initial development.
 Integration Testing: Expands testing to how the database interacts with other application
components like the UI, APIs, middleware, etc.
 System Testing: Testing the entire system end-to-end, including the production-like database, to
validate functional requirements.
 Performance Testing: Executing load and stress testing at expected production loads early on and
continuing through staging environments.
age 21 of 28

 User Acceptance Testing (UAT): Having end users test with real-world scenarios and data to confirm
the system handles required use cases.
 Regression Testing: Retesting the database anytime changes are made to confirm no new issues
were introduced.
 Production Monitoring: Continuously monitoring database health, performance metrics, and logs
after going live.

This testing across the entire development lifecycle helps minimize defects and ensures optimal database
performance.

Database Testing Process

The key phases in structured database testing process include:

Planning

Defining the scope, objectives, timeline, environment needs, and resources required. Identify relevant
test conditions like target database, tooling, test data, etc.

Analysis

Study the database schema, architecture, and components to identify key areas to test like performance-
critical queries or tables, security controls, etc.
age 22 of 28

Test Design

Outline test cases that evaluate the desired functionality, performance, security, and data integrity per
requirements. Effective test cases include clear objectives, setup steps, test data, input values, expected
results.
Test Execution

Run designed test cases while recording results — passed, failed, blocked. Failed and blocked cases are
investigated and usually re-run after resolving underlying issues.

Defect Reporting

Log any defects uncovered and track them through resolution. Defect reports typically detail repro steps,
actual vs expected results, screenshots, stack traces, database logs, etc.

Test Closure

Final check of open defects and validation of fixes. Summary reports detail scope covered, successes,
challenges, and remaining risks if any.

Types of Database Testing

Some common database testing types include:


age 23 of 28

Functional Testing

Validating database operations and components deliver expected functionality per specifications:

 SQL Statements: Test INSERT, SELECT, UPDATE, DELETE, JOINs, etc.


 Procedures and Triggers: Verify programmatic elements like stored procedures execute properly.
 Permissions and Access: Confirm users can access data they should but not unauthorized data.
 Queries and Reports: Check reports return expected results.

Schema Testing

Evaluate database schema structure including:

 Table definitions — columns, data types, keys, constraints, etc.


 Relationships — foreign keys, cardinality between tables.
 Triggers and stored procedures.

Data Integrity Testing

Check data accuracy and consistency across database:

 Data Validation: Confirm expected data formatting, types, field lengths, mandatory fields, etc.
 Referential Integrity: Ensure no orphan records exist that break foreign key relationships.

Performance Testing

Test database responsiveness under expected load:

 Load Testing: Gradually increasing users and transactions.


 Stress Testing: Maxing out database resources — memory, CPU, IO.
 Scalability Testing: Adding resources like servers to handle more load.

Volume Testing

Test ability to handle large amounts of data through tactics like:

 Populate database with production-sized datasets.


 Simulate writes at peak rates from many concurrent connections.

Failover and Recovery Testing

Validate successful failover setup and backup processes by:

 Shutting down primary database server.


 Reroute connections to standby server.
 Restore database from backup files.
age 24 of 28

Security Testing
Attempt breaches from outside through exploits like SQL injection or unauthorized insider access.

Upgrade Testing
Test migrations to new RDBMS versions.

Regression Testing
Retest previously functioning components after any changes.

User Acceptance Testing


Have end users validate real-world scenarios and UI workflows.

Test Environments
Database testing requires environments that mirror production:

 Development: Used for initial unit and integration testing. Allows iterative coding without
corrupting real data.
 QA/Staging: Isolated environment with production-sized data, users, transactions. Essential for
performance, load, UAT testing before going live.
 Production: The live database used by end users. Continuously monitored and tested in production.

Virtual environments make replicating production easier without need to copy real data into lower
environments.

Common Databases Tested


While testing concepts are similar across databases, it helps to know syntax and tools specific to each
platform:

MySQL
Popular open source database. Test using SQL statements, MySQL Workbench GUI, Percona Toolkit.

Oracle
Leading enterprise database. Test with PL/SQL, SQL Developer, Oracle SQLcl.

Microsoft SQL Server


Top database for Windows environments. Test using T-SQL, SQL Server Management Studio, Visual
Studio.

PostgreSQL
Advanced open source SQL database gaining popularity. Test via psql, pgAdmin, PL/pgSQL.

MongoDB
Leading NoSQL document database. Validate using mongo shell, pymongo, Atlas cloud.

Cassandra
High performance NoSQL column store. Test with CQL, cqlsh, DataStax Studio.
age 25 of 28

IBM DB2
Mature enterprise database. Test through DB2 CLP, IBM Data Studio, JCL.

Key Database Testing Tools

Specialized tools simplify planning, automating, managing, and reporting on database tests:

 SQL Clients: Execute SQL statements — MySQL Client, Oracle SQLcl, psql
 Database IDEs: Develop and debug — Toad, SQL Developer, SSMS
 Diff Tools: Compare dataset differences — Toad, SQL Data Compare
 Executable Specifications: Auto-generate tests from requirements — SpecFlow
 Test Data Management: Rapidly provision test data — Delphix, CA Data Manager
 Performance Monitoring: Analyze bottlenecks under load — SolarWinds DPA
 Test Management: Document and track execution — TestRail, Kualitee
 CI/CD Pipelines: Automate deployments and testing — Jenkins, Bamboo
age 26 of 28

Teachers Activity:
Ask Question
Show Presentation
Demonstration
Show video:
https://www.youtube.com/watch?v=wR0jg0eQsZA

Reference:
Site:
https://www.google.com/
https://www.youtube.com/
https://www.lucidchart.com/pages/database-diagram/database-models#:~:text=A%20database
%20model%20shows%20the,data%20model%20the%20designers%20adopt.
https://www.geeksforgeeks.org/attributes-and-its-types-in-data-analytics/
https://www.w3schools.com/sql/sql_datatypes.asp
https://ifacet.iitk.ac.in/knowledge-hub/data-structure-with-c/data-structure-design-principles-and-best-
practices-for-creating-efficient-and-scalable-data-structures/
https://medium.com/@sikirus81/database-testing-a-complete-guide-81e2b81b48c3

eBook:
 Database Design and Implementation by: Dr. Weiru Chen
 Database Design – 2nd edition by: Adrienne Watt and Nelson Eng

Assessment 19-1:
age 27 of 28

Written Test

Test I: True or False: Write the letter T if the statement is true and F if the statement is false on the
space provided.

_____________ 1. Data structures serve as the foundation for more complex applications
_____________ 2. Most computer programming languages’ standard base data types, such as
integers or floating-point numbers, are typically insufficient to convey the
logical intent for data processing and application.
_____________ 3. Reduce used memory usage by selecting the right data types and storage-
optimizing techniques. Think about the trade-offs between time
complexity and memory utilization.
_____________ 4. Create modular, reusable data structures for your applications.
_____________ 5. Benchmark the performance of your data structures after thoroughly
testing them with representative data sets.
_____________ 6. Reduce the amount of needless data copying to save overhead. Use
pointers or references to share data between data structures whenever
possible to avoid duplicating data.
_____________ 7. Performance can be greatly enhanced by using modeling techniques.
_____________ 8. Scalable data structures can manage to expand or shift data sizes.
_____________ 9. To make the best use of system resources like time and memory, data
structures should be created.
_____________ 10. The process of development and organization of data structures that can
effectively store, manipulate, and retrieve data in a computer program or
system is termed data structure design.

Test II: Question and Answer

A: What is a Database Model?

_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

B: What is the meaning of attribute?

_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

C: What are data types?

_____________________________________________________________________________________
_____________________________________________________________________________________
age 28 of 28

_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________

Test III: Multiple Choice: Write your chosen letter on the space provided.

__________ 1. _____________________, analyze bottlenecks under load.


a. CI/CD Pipeline b. Test Management c. Performance Monitoring
__________ 2. _________________, automate deployments and testing
a. CI/CD Pipelines b. Test Management c. Performance Monitoring
__________ 3. __________ environments make replicating production easier without need
to copy real data into lower environments.
a. Real b. Virtual c. Setup
__________ 4. ______________ is used for initial unit and integration testing.
a. Production b. Development c. Staging
__________ 5. ______________ is the live database used by end users.
a. Production b. Development c. Staging
__________ 6. Attempt ____________ from outside through exploits like SQL injection or
unauthorized insider access.
a. maintenance b. repair c. breaches
__________ 7. Database testing refers to the process of _________ a database system to
verify it meets requirements and performs as expected.
a. reading b. crossing c. checking
__________ 8. Database testing is an important step in ____________data loss and
corruption,
a. minimizing b. Maintaining c. maximizing
__________ 9. Developers should create _________ test cases that target individual
database components like triggers, procedures, queries, etc.
a. medium-level b. low-level c. high-level
__________ 10. Having _______ users test with real-world scenarios and data to confirm the
system handles required use cases.
a. front b. end c. drug

You might also like