What are the potential pitfalls of storing comma-separated values in a database instead of normalizing the data?

Storing comma-separated values in a database can make it difficult to query and manipulate the data efficiently. It can lead to data redundancy, inconsistency, and make it challenging to maintain data integrity. Normalizing the data by breaking it into separate tables can help improve data organization and reduce the likelihood of errors.

// Example of normalizing data by creating separate tables for related information

// Table for storing users
CREATE TABLE users (
    id INT PRIMARY KEY,
    username VARCHAR(50),
    email VARCHAR(50)
);

// Table for storing user roles
CREATE TABLE user_roles (
    user_id INT,
    role VARCHAR(50),
    FOREIGN KEY (user_id) REFERENCES users(id)
);