'How to store a business rule table(9x9)

I am completely stumped.

I have students that can test their listening skills in a language and the customer wants to be able to change the business rules on demand, the actual business rules and conditions are much more advanced, so I am doing my best to simplify.

I have my object for the student:

public class Student {
  public string Name { get; set; }
  public int Score1 { get; set; }
  public int Score2 { get; set; }
  public int Age { get; set; }
  public string Language { get; set; } 
}

Example Business Rule:

There are multiple business rules, but I will give an example below:

  • Condition: If the language is Spanish && they are older than 55
  • Business Rule Table: First Row is the score for Score1, First Column is the score for Score2, rest of the data is the value to take when making the comparison.
1 2 3 4 5 6 7 8 9
1 Fail Fail Fail Retake Retake Retake Retake Retake Retake
2 Fail Fail Fail Retake Retake Retake Retake Retake Retake
3 Fail Fail Fail Retake Retake Retake Retake Retake Retake
4 Retake Retake Retake 4 Retake Retake Retake Retake Retake
5 Retake Retake Retake Retake 5 Retake Retake Retake Retake
6 Retake Retake Retake Retake Retake 6 Retake Retake Retake
7 Retake Retake Retake Retake Retake Retake 7 Retake Retake
8 Retake Retake Retake Retake Retake Retake Retake 8 Retake
9 Retake Retake Retake Retake Retake Retake Retake Retake 9

Examples for how it works:

  • Ex1:
    • IF Score1 = 4,
    • AND Score2 = 5,
    • THEN Calculation = Retake
  • Ex2:
    • IF Score1 = 6,
    • AND Score2 = 6,
    • THEN Calculation = 6

Requirement:

These business rules need to be put into a SQL table, so they can change the conditions and the outcomes based on the scores, on-demand and track who made the change. Each language(12) will have its own business rules.

Also have the ability to add a business rule on the fly

Questions:

  • I know it is not recommended, but what is the best way to implement something like this in SQL?
    • Method 1: Two Tables
      • Table1:
        • Conditions for when it should be applied
        • Modified By
        • Modified At (Timestamp)
      • Table2:
        • 81 columns for each of the cells of the Business Rule Table
    • Method 2: One table
      • Table:
        • Conditions for when it should be applied
        • Business rule table as JSON string
        • Modified By
        • Modified At (Timestamp)

Problems:

  1. Storing these in SQL will be messy
  2. The string values in the BR table are values from a lookup table, that is editable, and will need to be linked
    • ex: "Retake" & "Fail"


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source