开发者

Structure of a database for a big system

I want to create a simple web app that will have a connection from users to items. Let's say each user will have some items assigned to him (in this case, series and episodes, and a lot of them).

How should I plan the database structure for a system like this one (tables, fields and so on)? It's the first time开发者_如何学运维 I encounter such a case.


Looks like a typical M:N association.

create table person (
  id number not null primary key,
  username varchar not null, -- login
  -- email, etc
);

create table episode (
  id number not null primary key,
  ordinal number not null, -- which episode in the series
  name varchar not null, 
  -- whatever else, for instance, a link to series:
  -- series_id not null number foreign key referencing series(id)
);

-- the link table you asked about
create table person_x_episode (
  person_id number not null foreign key referencing person(id),
  episode_id number not null foreign key referencing episode(id),
  -- whatever else, like seen date, rating, etc
);

If you need series and seasons subdivision, or groups of users, etc, you'll have more tables.


The basics are a table of users and a table of items. These are sometimes called "master" tables. Then you have a cross-reference table, users-items, that has a foreign key to items and a foreign key to users. This is sometimes called a "many-to-many" table.

As for columns and other details, you'd have to tell us a lot more about what you are trying to keep track of. Generally, each fact becomes a column in the table. So for a TV series (i'm guessing here cuz you didn't tell us much) you would have perhaps a column for the season, season 1, season 2, etc., the year that season came out.

Perhaps then a child table of the items table (which maybe should be called series) that lists the stars during that season.

If you provide more details, I can edit the answer a bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜