An easy guide to  understanding databases

An easy guide to understanding databases

A beginners introduction to databases

Every web application you use has a way to store and manage the information you have access to, and this information is kept in a database.

In this article, you will learn about databases. By the end of this article, you should be able to understand the following:

  • The similarities between data, information, and knowledge

  • What is a database

  • Advantages of database

  • Types of databases

  • Database management system etc

Let's get started

Introduction

Consider a scenario where you stumbled upon this awesome website that enables you to sell slightly used household items. You visit the website and are required to create an account to get started.

There is a sign-up form on the screen asking for the following details:

  • First and last name

  • Username

  • Email address

  • Password

  • City

You proceed to enter these details and you clicked on the "Sign up" button.

What is the use of the information you just submitted, where is it stored, and who has access to it?

  • The information you provided is referred to as data, and this information is stored and managed on the web server in a database.

  • The web server will use this information to track certain actions you perform on the site. For instance:

    • Verify your logged-in details whenever you attempt logging in to the site

    • Publish any new item you want to sell

    • Notify you whenever a user interacts with a posted item etc.

Consider another instance, where you want to inform users of the website you have a slightly used sofa to sell.

You visit the website and you are required to log in with an email address and password, so you enter the email address and password you used when creating the account and clicked on the login button.

What happens to the information you submitted?

Once submitted, the website will go to a place where all this information is kept and verify if the information (email address and password) you submitted matches any of the information they have available. If there is a match, you are allowed access to the website to post your item.

Finally, you proceed to sell your first item, the website has a form where you can enter the name, and description and upload an image of the item to sell.

You then clicked on the post button to submit the information so all users of the website can view your item

Where does this information go to?

A major component of all dynamic websites or web apps is the database.

It is the location where all entered information is stored. A database is composed of data.

  • Data can be any information you submit on the website

  • The database will refer to where the information is being kept and managed

Let's dive deeper to understand what these terms mean.

Similarities between data, information, and knowledge

Data

Data is information with no context that is collected in various formats such as text, numbers, media, etc. either individually or as a set.

For instance, if I give you the numbers, "21, 35, 14, and 5", I would've given you data but you have not learned or gained anything from the data presented.

There are two types of data: quantitative and qualitative. Whiles quantitative data is numeric, qualitative data is descriptive, for instance, "red car", "first name", "email address" etc.

Information

In order for data to be useful, it needs to be in context. For instance, if I told you the numbers "21, 35, 14, and 5", are the ages of users that viewed my website, that would be information.

By adding context, we have converted data into information

Knowledge

Whenever we put data into context, aggregate it, and analyze it, we can use it to make decisions. The utilization of information produces knowledge. This knowledge can be used to set policies, make decisions and generate conversation.

In broad terms, data can be a collection of information. For instance, in a social media application, data can be a collection of

  • number of users

  • All user email addresses

  • All posts made by a specific user

  • number of posts a user has made etc

What is a database?

A database is an organized collection of related information (data) that is stored in a way that it can be easily accessed, retrieved, managed, and updated.

It is where all data is stored and organized in a way for the end-user to retrieve, manage and edit. The data can be orders, customer information, inventory, etc.

An analogy of a database could be a library that houses a wide range of books. In this analogy, each book is data, and the library is the database.

The objective of many web apps is to convert data into information to help generate knowledge useful for decision-making.

To achieve this, the app must be able to accept the data, put the data into context, and provide tools for aggregation and analysis. A database is designed for such a purpose.

In a database, all data is described and associated with other data(organized collection). All the information in a database should be related as well. A separate database should be created to manage unrelated information.

For instance, a database that contains information about customer details should not hold information about company stock prices.

Uses of databases

Generally, databases are used for data processing operations. The operations could be the Create, Read, Update, and Delete (CRUD) operations.

Using a programming language, web apps can store or retrieve data from databases.

Typical uses of databases are:

  • Storing and retrieving different types of data

  • Persisting information for future use

  • Aggregating, sorting, filtering and processing data for analysis

  • Establishing the relationship between all the stored data.

Types of databases

There are numerous databases available. These includes

  • Hierarchical databases

  • Relational databases

  • Non-relational databases

  • Object-oriented databases

Hierarchical databases

A hierarchical database is a data model in which data is stored in the form of records and organized into a tree-like structure, or parent-child structure.

Its structure is similar to a family tree. A parent has one or more children beneath it. Hierarchical databases provide easy access and quick querying increasing their performance.

An example of a hierarchical database is the Windows registry.

Example of Hierarchical database

Relational databases

Relational databases organize data into tables with columns and rows.

The rows also known as records describe a collection of related values. Each row is identified by a unique key. The fields of the table form a column.

In a relational database, information is stored in tables containing specific types of data. For instance, a shop could store details of their customer's names and addresses in one table, and details of their orders in another.

These separate tables can be joined together by fields known as foreign keys. For instance, the customer table can be joined to the orders table

Whenever data is added to a relational database, new records are inserted into the existing tables, and relationships can be formed between these tables.

It generally uses Structured Query Language (SQL) to perform tasks such as creating, reading, updating, and deleting (CRUD) data.

Examples of relational databases are MySQL, Microsoft SQL Server, and Oracle.

Non-relational databases

Non-relational databases commonly referred to as NoSQL databases do not use the tabular schema of rows and columns. There is no relation at all between the tables.

In a non-relational database, data is represented as an object or JSON-like documents. The document contains different types of information in varying formats. It is mostly made up of key:value pairs.

Document databases help developers to store and query data in a database by using the identical document model format that they use in their application code.

A single stored data might have different attributes or fields from the next piece of data in the same database

Databases that are non-relational are great if you don't know exactly the data you need to store, or if you have a lot of data with different attributes but you still need to compare them.

It is possible to develop applications that require a dynamic database that can change rapidly and accommodate large amounts of complex, unstructured data using non-relational databases.

For instance, in a NoSQL database, each customer has their own document containing all of their information.

A customer record is usually stored as a JSON document. The name, city, email address, phone number, purchase history, credit card information, etc are stored as attributes in a single document.

This helps data to be optimized for intuitive development and horizontal scalability.

Examples of non-relational databases include MongoDB. Apache Cassandra, Couchbase, Redis, etc.

Object-oriented databases

An object-oriented database is a type of database that is based on the principles of object-oriented programming (OOP). With an object-oriented database, data is organized and stored as objects, which are self-contained units that contain data and the methods that can be applied to it.

They are mainly used in applications that demand integration of varying data types and sources, high performance, calculations, and rapid results.

It enables you to store multimedia data like pictures, audio video, and other types of data that are generally not recommended to store in relational databases.

Examples of applications that use object databases are real-time systems. architectural and engineering for 3D modeling, and scientific products.

Database management systems (DBMS)

Specific software is required to enable you to create, read, update, and delete data in the database.

To analyze the data or change the database structure, you also require software. These software applications are commonly referred to as database management systems (DBMS)

Database Management System or DBMS is a type of software that powers the management of a database. It can be used to find and update data in a database as well as analyze and generate reports. It also provides a layer of security to the database.

Advantages of DBMS

The advantages of DBMS are outlined below

  • Data Security: DBMS ensures data security and privacy by enforcing authentication and access control measures

  • Data Integrity: Data must be safe from corruption, loss, and outside attack. DBMS provides this integrity by ensuring regular archiving, backups, data audits, input validations, removing redundancies, etc

  • Quick Access: DBMS ensures that users can retrieve and store data effortlessly.

  • Backup and Recovery: DBMS can be designed to take care of periodic backup and recovery in case of failure

Examples of DBMS

Popular examples of database management systems (DBMS) are:

  • MySQL

  • MongoDB

  • MariaDB

  • PostgreSQL

  • Oracle

  • Cassandra

Designing a database

Software developers are required to not only know how to use a database but be well-equipped to design a database.

A properly designed database gives you access to up-to-date, accurate information.

Steps in Designing a relational database

The following steps provide general guidance on how to design a relational database

  • Define the database goal

  • Define the requirements for the various stakeholders

  • Define the database entities in terms of tables

  • Identify and define the attributes of each entity

  • Specify the primary and foreign key constraints for each relational table

  • Define and establish relations between each table

  • Apply the database normalization rules to normalize the table

  • Create and build the database using the DBMS

In our next article, we will learn how to design a database.

Summary

In this article we learned that:

  • Data can be any information you submit on the website

  • The database will refer to where the information is being kept and managed.

  • There are varying databases, these are relational,non-relational, hierarchical, and object-oriented database

  • DBMS is a specific software required to enable you to create, read, update, and delete data in the database. Examples are MySQL, MongoDB, PostgreSQL, etc