DEV Community

Elvis Kwabena Asare Nkrumah
Elvis Kwabena Asare Nkrumah

Posted on

Making RDBMS Simple: What's Up with the First Normal Form?

Introduction:

Hey there! Ready to explore the world of databases? We're starting with a cool topic: normalization. Today, we're talking about the First Normal Form (1NF). It might sound fancy, but don't worry, we'll break it down into easy bits. Let's dive in!

Scenario 1:

Imagine you're building a library database to keep track of books. At first, you might think, "Let's put everything about a book in one place—title, author, genre, and if it's available." Sounds good, right? But as your library grows, things get messy.

Enter the First Normal Form:

So, what's this 1NF thing? It's like the hero that saves your data from being a mess. It tackles two main problems: too much repeated info (we call it redundancy), and making sure each piece of info is simple and clear (that's atomicity).

Let's take note of the following key terms:

  1. Redundancy: This is when you have the same info in different spots. 1NF helps us get rid of this mess and keeps things neat.

  2. Atomicity: Fancy word, simple idea. It means each column (like title or author) should have just one type of info. And every piece of info should be simple, not a mix of things.

Putting it into Action:

Let's make our library database! We'll use two tables – one for authors and another for books.

-- Table: authors
CREATE TABLE authors (
    author_id INT PRIMARY KEY,
    author_name VARCHAR(255) NOT NULL
);

-- Table: books
CREATE TABLE books (
    book_id INT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    genre VARCHAR(50),
    availability BOOLEAN,
    author_id INT,
    FOREIGN KEY (author_id) REFERENCES authors(author_id)
);
Enter fullscreen mode Exit fullscreen mode

This code creates two tables. One for authors, keeping things like their ID and name. The other is for books, linking back to the authors. Easy, right?

Scenario 2:
Consider the mock database below:

A mock database
This table structure violates 1NF because the 'Skills' attribute is multivalued. This means that a single employee can have multiple skills.

Implementing 1NF:

To transform the mock database into 1NF, we need to address the multivalued attribute in the 'Skills' column. We can create a separate table named 'EmployeeSkills', with the following structure:

database in 1NF

This new table establishes a many-to-many relationship between the 'Employees' and 'EmployeeSkills' tables, ensuring that each employee is associated with a unique set of skills.

Conclusion:

Great job! You've just conquered the basics of the First Normal Form. This simple rule helps us make databases that are organized, grow-friendly, and easy to understand. Stick around for more fun database stuff in our next chat!

Top comments (0)