Zergi is more than right.
He didn't make his point strong enough, if anything.
Quote:
|
I have to make the DB such that everytime I add a user, a set of tables must be inserted (e.g 30 days, one table for each day)
|
This is probably *THE VERY WORST DESIGN* I have seen for a database in the last 14 years of answering database questions in various forum.
The *ONLY* point where I disagree, in a minor way, with Zergi is here:
Quote:
|
id, user_id, channel_id, watch_time
|
The
id column there is completely unneeded. It serves no purpose, at all.
For this table, the combination of the other three fields forms a perfect PRIMARY KEY and should be so code:
Code:
CREATE TABLE channel_watch (
user_id INT NOT NULL,
channel_id INT NOT NULL,
watch_time DATETIME NOT NULL,
PRIMARY KEY ( used_id, channel_id, watch_time ),
CONSTRAINT FOREIGN KEY user_id REFERENCES users(user_id),
CONSTRAINT FOREIGN KEY channel_id REFERENCES channels(channel_id)
) ENGINE INNODB;