简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM