How can database normalization be implemented to simplify the updating process?
Database normalization can simplify the updating process by reducing data redundancy and ensuring data integrity. By breaking down data into separate tables and establishing relationships between them, updates only need to be made in one place, rather than multiple locations. This reduces the risk of inconsistencies and makes updating more efficient.
// Example of implementing database normalization in PHP using MySQLi
// Establish connection to database
$connection = new mysqli("localhost", "username", "password", "database");
// Create a table for users
$connection->query("CREATE TABLE users (
id INT PRIMARY KEY,
username VARCHAR(50),
email VARCHAR(50)
)");
// Create a table for user addresses
$connection->query("CREATE TABLE user_addresses (
id INT PRIMARY KEY,
user_id INT,
address VARCHAR(100),
FOREIGN KEY (user_id) REFERENCES users(id)
)");
// Update user's email address
$user_id = 1;
$new_email = "newemail@example.com";
$connection->query("UPDATE users SET email = '$new_email' WHERE id = $user_id");
// Close connection
$connection->close();