首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数据库设计/ mysql

数据库设计/ mysql
EN

Stack Overflow用户
提问于 2012-01-04 22:31:49
回答 3查看 138关注 0票数 1

我的客户想要在他们的网站上添加新的功能,他们与演员/模型打交道,并希望能够为每个客户创建信用记录(很像简历或简历)。

他们有一些我必须遵守的标准,正因为如此,我无法理解它。

信用可以是两种情况之一,它可以是4列信用,也可以是单列信用。然而,信用必须有一个类别,这些类别可以是以下之一,电视,电影,广告,广播或自己制作的东西。

第二个标准是类别是可排序的,因此,例如,如果他们正在输入演员的片头,他可能会有电视和电影片头,他们可能会时不时地在电视上拍摄电影。

第三个标准是每个类别的积分都是可订购的,因此film1积分不必位于顶部。

这是我到目前为止设计的东西。

代码语言:javascript
复制
CANDIDATES     |      CREDITS  
----------            -------    
candidate_id^         credit_id*
                      credit_category  
                      credit_heading
                      credit_title  
                      credit_role  
                      credit_director
                      credit_position  
                      candidates_candidate_id^^ 

^-主键

^^ -外键

我的困惑来自于使用这种表结构无法改变类别的顺序,就像我添加了一个credit_category_position一样。

例如,如果用户在类别电影中有一个信用,而我想添加另一个,当我通过我的表单插入数据时,我如何保持所有客户电影条目的credit_category_position一致?

我希望这对某些人来说是有意义的。

EN

回答 3

Stack Overflow用户

发布于 2012-01-04 22:42:16

我只是浏览了一下你的问题,我不确定我是否完全理解了它,但有一件事突然出现在我的脑海中:

为什么不在candidatescredits之间建立一个many-to-many relationship

代码语言:javascript
复制
CANDIDATES     |      CREDITS  
----------            -------    
candidate_id^         credit_id*
                      credit_category  
                      credit_heading
                      credit_title  
                      credit_role  
                      credit_director


CANDIDATE_CREDIT_REL
--------
rel_id*
credit_id^^
candidate_id^^ 
credit_position  
票数 0
EN

Stack Overflow用户

发布于 2012-01-04 23:06:34

信用可以是两种情况之一,它可以是4列信用,也可以是单列信用。

我将跳过这一部分,因为我不理解它,而且您的描述中没有任何内容可以帮助我解决它。请随时编辑您的问题。

第二个标准是类别是可排序的

你需要一个额外的表格,因为每个候选人可以有多个学分,比如说电影。

代码语言:javascript
复制
create table credit_category_order (
  candidate_id integer not null,
  credit_category <whatever> not null,
  category_order float not null, -- lets you reorder by splitting the difference,
                                 -- but there are other ways.
  primary key (candidate_id, credit_category),
  foreign key (candidate_id, credit_category) 
    references credits (candidate_id, credit_category)
);

第三个标准是每个类别的积分都是可订购的

将列添加到制作者名单。查询时,连接credit_category_order和ORDER BY credit_category_order.category_order, credits.credit_order

票数 0
EN

Stack Overflow用户

发布于 2012-01-04 23:22:37

代码语言:javascript
复制
Credit_Category
----------
id, category_name, details


Actor_cc_order  //For each actor, have an entry for every category
----------
id, id_actor, id_cc, ord_number


Actor_credit
------------
id, id_actor, id_cc, credit_details

查看制作者名单

代码语言:javascript
复制
SELECT a.*, b.category_name, c.ord_number  FROM
Actor_credit a
JOIN  Credit_category b ON b.id = a.id_cc
JOIN  Actor_cc_order c ON c.id_actor = a.id_actor AND c.id_cc = b.id
SORT BY a.id_actor, c.order_number
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8728514

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档