Why is it important to normalize database tables and avoid creating a separate table for each room when storing related data in MySQL?
It is important to normalize database tables in order to reduce data redundancy and improve data integrity. Creating a separate table for each room would result in duplicated data and make it difficult to update or maintain the database. By normalizing the tables, related data can be stored in a structured manner with proper relationships between tables.
// Example of normalizing database tables in MySQL
// Create a table for rooms
CREATE TABLE rooms (
room_id INT PRIMARY KEY,
room_name VARCHAR(50)
);
// Create a table for related data
CREATE TABLE room_data (
data_id INT PRIMARY KEY,
room_id INT,
data_value VARCHAR(50),
FOREIGN KEY (room_id) REFERENCES rooms(room_id)
);