在数据库

时间:2017-04-18 09:54:02

标签: sql-server tsql database-design

我有以下SQL表:

create table dbo.Basket ( 
  Id int not null
  Name nvarchar (80) not null
)

create table dbo.Product ( 
  Id int not null
  Name nvarchar (80) not null,
  Price decimal not null
)

create table dbo.BasketProduct ( 
  BasketId int not null,
  ProductId int not null,
)

我有不同的方法来创建一个篮子。例如:

  1. N个产品的总价格在200美元到240美元之间;
  2. 8种产品最便宜5美元,最贵40美元;
  3. ...
  4. 在我的应用程序代码中,我确定将构建该方法的方式。

    但我想保存所应用的规则,以便我知道未来每个篮子的构建方式。

    我选择不同的选项:

    1. 将算法生成的SQL保存在表中。 这个问题是我需要知道所使用的每个参数的具体值。

    2. 将条件保存在表格中。例如:

      -TotalProducts = 8
      -CheapestProductPrice = 5
      -MostExpensiveProductPrice = 40
      -ProductCategories = Book,CD

      在这种情况下,我不确定是否存在一种在数据库上保存条件的规范化方法。

      一个看起来很奇怪的条件是有一个枚举的条件。 例如:ProductCategories=Book,CD

    3. 也许有一个包含公式的表,然后每个篮子都有一个使用公式的FK及其参数的值?

    4. 有人可以就此提出建议吗?

0 个答案:

没有答案