Book Image

MariaDb Essentials

By : Kenler
Book Image

MariaDb Essentials

By: Kenler

Overview of this book

This book will take you through all the nitty-gritty parts of MariaDB, right from the creation of your database all the way to using MariaDB’s advanced features. At the very beginning, we show you the basics, that is, how to install MariaDB. Then, we walk you through the databases and tables of MariaDB, and introduce SQL in MariaDB. You will learn about all the features that have been added in MariaDB but are absent in MySQL. Moving on, you’ll learn to import and export data, views, virtual columns, and dynamic columns in MariaDB. Then, you’ll get to grips with full-text searches and queries in MariaDb. You’ll also be familiarized with the CONNECT storage engine. At the end of the book, you’ll be introduced to the community of MariaDB.
Table of Contents (10 chapters)
9
Index

Foreign keys

As you know, relationships exist between the tables in a relational database. This means that the rows in a table are usually associated to the rows in another table or multiple tables.

Creating relationships between tables

Let's see an example. Suppose that our online store sells several types of products. We don't want to display them all together, because it would be confusing for most users. Instead, we need to separate our products by category.

Creating relationships between tables

So, first we will create a table for the product categories. We need to store the category name, a description, and of course an id that will be the primary key:

CREATE TABLE product_category
(
  id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(50) NOT NULL,
  description TEXT NOT NULL,
  UNIQUE INDEX unq_name (name)
)
  DEFAULT CHARACTER SET utf8
  ENGINE = InnoDB;

Of course, this table will not be useful unless we also have a way to associate each product to one category. To do this, we will create a new column...