View Single Post
Old 01-28-2013, 03:23 AM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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;
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote