Get job ready skills with Codenga     |       Career Paths 35% OFF     |        Limited time only

02h 52m 18s
close
Cart icon
User menu icon
User icon
Lightbulb icon
How it works?
FAQ icon
FAQ
Contact icon
Contact
Terms of service icon
Terms of service
Privacy policy icon
Privacy Policy
Poznaj podstawy baz danych

Introduction to databases

Databases are a crucial element of almost every application that requires data storage. In this article, we will discuss the key concepts related to databases.

What is a database

A database is an organized collection of data that is stored in such a way as to allow easy access, manipulation, and management of the information.

Imagine a database as a gigantic, virtual box where you can store your data. Inside this box, the data is organized into tables or collections, each of which can represent a specific type of information. For example, in an e-commerce application, we can have tables with data about products, customers, orders, etc.

Advantages of using databases:

  • Easy data access: Databases provide a convenient and efficient way to access data, allowing users to retrieve the information they need quickly and without hassle.
  • Persistent data storage: Data stored in databases is durable and remains intact even after the application is turned off or restarted. This ensures that important information is not lost between sessions.
  • Concurrent data access: Databases support multiple users accessing and manipulating data simultaneously. This means that multiple users can work with the data concurrently without conflicts.
  • Fast data retrieval: Databases are optimized for fast data retrieval, enabling swift searches and access to specific pieces of information within large datasets.
  • Data consistency: Databases are designed to maintain data consistency, meaning that the data stored remains accurate and reliable throughout various operations and interactions.

Different types of databases

There are many different types of databases, and the choice of the appropriate type depends on the nature of the data that the application needs to store, as well as the requirements for performance and scalability.

Relational databases (RDBMS)

Relational databases are one of the most popular types of databases. Data is stored in tables, and relationships between tables are defined using foreign keys. Examples of popular Relational Database Management Systems (RDBMS) include:

  • MySQL
  • PostgreSQL
  • Microsoft SQL Server
  • Oracle Database
  • SQLite

NoSQL databases

NoSQL (Not Only SQL) databases are a diverse set of databases that do not follow the traditional table-based and relational model used in relational databases. Instead, NoSQL databases often utilize different data structures, such as documents, graphs, or columns. Examples of NoSQL databases include:

  • MongoDB
  • Neo4j
  • Cassandra
  • Redis

Relational databases

Let's now look at the key concepts related to relational databases.

The method of data storage

Data is stored in tables, which consist of rows and columns. Each table represents a specific type of information, for example, a table for customer data, a table for products, or a table for orders. A key element of a relational database is the ability to establish relationships between different tables using foreign keys, allowing data to be linked across various tables.

Table and columns

In a relational database, a table is a collective container that stores data with the same characteristics or data types. Each table consists of columns that define different properties or attributes of the data. For example, a table containing customer data may have columns such as Customer ID, First Name, Last Name, Address, and Email Address.

Primary Key and Foreign Key

In each table, you can define a primary key, which uniquely identifies each row in the table. The primary key must be unique within the table, allowing for easy retrieval and updating of specific records.

A foreign key is a field in a table that is linked to the primary key in another table. This allows for establishing relationships between tables. For example, in an orders table, we can use a foreign key to point to a customer in the customers table who placed that order.

Advantages of relational databases:

  • Structure and consistency: Relational databases offer a well-defined structure, helping to maintain data consistency and avoid duplication.
  • Data access: The SQL language provides easy access to data and allows for filtering, sorting, and grouping query results.
  • Data management: Relational databases offer advanced data management features, such as indexes, transactions, and constraints, which help in maintaining data integrity.

SQL language

And since the topic of the SQL language has come up, it's definitely worth mentioning a few words about it. It is a standard language for managing relational databases. W ith its help, we can retrieve data from the database, insert new data, modify data, and perform various administrative operations.

SQL operations - an example

In SQL, you can perform various data-related operations. Let's look at a simple example:


SELECT name, address FROM customers WHERE age > 18;

This code snippet is a SQL query. It allows us to read the contents of a table named "customers." We are extracting data from the "name" and "address" columns. At the end of the query, there's a condition: we are interested in individuals whose "age" column has a value greater than 18.

We used this example to illustrate the concept of writing queries to the database using the SQL language.

NoSQL Databases

Databases classified as NoSQL (Not Only SQL) differ fundamentally from traditional relational databases. Unlike relational databases, NoSQL databases do not use the table and relation model. Instead, they utilize various data structures that are specifically tailored to different types of data and use cases. NoSQL databases have gained popularity due to their flexibility, scalability, and ability to handle large volumes of data in real-time.

Data storage - main approaches

Document Databases

Document databases store data in the form of documents, which can be in formats like JSON, BSON, XML, or others. Each document contains a set of keys and values that represent the properties of an object. These documents can be diverse, providing great flexibility in data modeling. Examples of document databases include MongoDB, Couchbase.

Columnar Databases

Columnar databases store data in columns, unlike traditional relational databases which store data in rows. This is particularly efficient when the application needs to process large amounts of data in a single query and requires only specific columns. Examples of columnar databases include Apache Cassandra and HBase.

Graph Databases

Graph databases are designed to store data in the form of graphs, which consist of vertices (nodes) and edges (relationships) between them. They are ideal for modeling and solving problems related to networks and connections between data. Examples of graph databases include Neo4j, Amazon Neptune.

Key-Value Databases

Key-value databases store data as a simple set of key-value pairs. They are exceptionally fast and scalable, making them popular in applications requiring rapid access to data. Examples of key-value databases include Redis, Riak.

Advantages and disadvantages of NoSQL databases

Databases of this type sometimes provoke controversy. They work perfectly in certain situations, but often using a relational database is a better choice. Everything, of course, depends on the requirements of the particular project.

Advantages

NoSQL databases offer significant flexibility in data modeling as they do not require a strictly defined schema, as is the case in relational databases. It is easy to add and modify data, facilitating application development and introducing changes to the data structure.

NoSQL databases, such as key-value or columnar databases, are highly efficient in executing simple queries on large amounts of data. Due to their specific storage structure, they allow for fast searching and data access, which is particularly crucial in applications with a large number of users.

NoSQL is well-suited for storing non-relational data, such as documents, graphs, or time-series data. In such cases, where the data structure may be complex and variable, NoSQL databases provide a more natural approach to data management than traditional relational databases.

Disadvantages

The lack of common standards among NoSQL databases can make choosing the right solution challenging. There are many different types of NoSQL databases, with various data structures and characteristics, which can lead to issues related to data uniformity and integration.

Compared to traditional relational databases, the community around NoSQL databases is usually smaller, and the availability of tools and support may be limited. This can affect problem-solving difficulties and gaining knowledge about specific databases.

Some NoSQL databases do not offer full transactional support, which is well-known in relational databases. This means that in case of failures or connection issues, data loss or incomplete operations may occur. In certain cases where strict data consistency is required, the lack of transactionality can be problematic.

Data modeling

Data modeling is the process of planning the structure of a database. In this process, the aim is to optimally design the data structure, relationships between data, and select appropriate field types. The ultimate goal is to build a database structure that enables efficient and consistent storage of information.

Summary and next steps

Now you know the key features of relational databases and NoSQL databases. If you want to learn how to work with data and relational databases from scratch, consider following the SQL Developer career path. This career path will make you a valuable SQL specialist, offering dozens of tasks and exercises to acquire practical skills that are in demand in the job market.