dov11020 2011-07-11 18:49
浏览 59
已采纳

mysql中有大量的外键? 这样好吗?

Hey guys (and probably girls). I'm modelling a huge database in mysql for a company that i work and i'm stucked on things that you might help me.

My question is very simple: How do i know that a number of foreign keys is enought ?

I have 8 tables that describes the following datas:

1st relationship

  • table country (pais)
  • table state (estado)
  • table city (cidade)

(city => state => country)

2nd relationship

  • table department (departamento)
  • table sector (setor)
  • table role (cargo)

(role => sector => department)

3rd relationship

  • legal entity (entidade juridica)
  • company (empresa)

(company => legal entity)

And finally i have a ninth table called employee and this table have foreign key references of all the tables previously described.


  • (primary) id-colab
  • fone_colaborador
  • fax_colaborador
  • ativo_colaborador
  • email_colaborador
  • (primary) cargo_id_cargo (cargo table)
  • (primary) cargo_setor_id_setor ( cargo table)
  • (primary) cargo_segor_departamento_id_departamento (cargo table)
  • (primary) empresa_id_empresa (empresa table)
  • (primary) empresa_entidade_juridica_id_entidade_juridica (empresa table)
  • (primary) empresa_entidade_juridica_cidade_cidade_id (empresa table)

  • (fK) cargo table

  • (fk) empresa table

The main concept of this model is.

  • I have a register of a legal entity.
  • legal entity must be placed on country => state => city

  • I have a register of a company

  • Company should inform whether it is a branch or parent company
  • Company should have a referece to the legal entity table (that owns address, phone, state id, city id, country id, postal code and etc...)

  • I have a register of a role

  • Role should have a reference to the sector table
  • sector table should have a reference to the department table

And finally, the main table called employee described on the image above.

I hope you guys have undertood me !

See ya.

  • 写回答

1条回答 默认 最新

  • douyong4842 2011-07-11 18:55
    关注

    You can have 100 foreign keys in your table if that's what's required to keep your data properly normalized. Don't worry about the number. Worry about keeping your fields appropriately atomic and your schema normalized.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件