To build a database structure for storing the operating days, time, and sessions for each company, you can use the following structure:
- Create a table for companies:
CREATE TABLE companies (
id INT PRIMARY KEY,
name VARCHAR(255),
...
);
- Create a table for operating days:
CREATE TABLE operating_days (
id INT PRIMARY KEY,
day VARCHAR(255)
);
- Create a table for operating times:
CREATE TABLE operating_times (
id INT PRIMARY KEY,
time_start TIME,
time_end TIME
);
- Create a table for sessions:
CREATE TABLE sessions (
id INT PRIMARY KEY,
session VARCHAR(255)
);
- Create a pivot table to establish the many-to-many relationship between companies, operating days, operating times, and sessions:
CREATE TABLE company_operating_hours (
company_id INT,
operating_day_id INT,
operating_time_id INT,
session_id INT,
FOREIGN KEY (company_id) REFERENCES companies(id),
FOREIGN KEY (operating_day_id) REFERENCES operating_days(id),
FOREIGN KEY (operating_time_id) REFERENCES operating_times(id),
FOREIGN KEY (session_id) REFERENCES sessions(id)
);
This structure allows you to associate each company with multiple operating days, times, and sessions. You can then query the data based on your requirements.
Note: The above structure is a basic example. You may need to modify it based on your specific needs and additional columns you want to include in the tables.