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.

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

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决