What are some best practices for designing a database for employee scheduling in PHP?
When designing a database for employee scheduling in PHP, it is important to create tables for employees, shifts, and schedules. Use foreign keys to establish relationships between these tables and ensure data integrity. Additionally, consider using a timestamp data type to track when shifts are scheduled.
CREATE TABLE employees (
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
role VARCHAR(50) NOT NULL
);
CREATE TABLE shifts (
id INT PRIMARY KEY,
start_time DATETIME NOT NULL,
end_time DATETIME NOT NULL
);
CREATE TABLE schedules (
id INT PRIMARY KEY,
employee_id INT,
shift_id INT,
scheduled_date DATE,
FOREIGN KEY (employee_id) REFERENCES employees(id),
FOREIGN KEY (shift_id) REFERENCES shifts(id)
);