Determine Keys from Functional Dependencies

前端 未结 6 2003
野趣味
野趣味 2020-12-22 23:43

I\'m taking a database theory course, and it\'s not clear to me after doing the reading how I can infer keys, given a set of functional dependencies.

I have an examp

6条回答
  •  一个人的身影
    2020-12-23 00:29

    Code

    If code talks to you more than long explanations, here is a 25 lines implementation of an algorithm that finds keys based on functional dependencies:

    https://github.com/lovasoa/find-candidate-keys/blob/master/find-candidate-keys.js

    Example

    candidate_keys(["A","B","C","D","E","F","G"], [ [['A','B'], 'C'], [['C','D'], 'E'], [['E','F'], 'G'], [['F','G'], 'E'], [['D','E'], 'C'], [['B','C'], 'A'] ]) returns [["B","D","F","G"],["B","D","E","F"],["B","C","D","F"],["A","B","D","F"]]

提交回复
热议问题