小编Pre*_*ids的帖子

为了完整性而去规范化是不是一个好主意?

我正在使用 Postgres 9.2 开发一个测验应用程序,在该应用程序中,我向用户展示了一系列问题并记录了他们的答案。

这些问题可以有多种形式——它们可能是多项选择(什么是 2 + 2?A:2。B:3。C:4),或者它们可能需要用户自己计算答案,在这种情况下我需要将他们的输入限制为“440”或“1/2”或“.333”之类的内容。一些问题可能会提示用户输入一篇文章。而且,当然,我以后可能需要添加更多类型的问题。

我设想的表格,以简化的形式,是这样的:

CREATE TABLE problems
(
  problem_id serial NOT NULL PRIMARY KEY,
  problem_type text NOT NULL, -- Refers to a lookup table
  answer_letter text, -- If not null, refers to the correct answer in the answers table below.
  response text -- If not null, represents a correct answer to be input, like '0.4'
);

CREATE TABLE answers
(
  problem_id integer, -- Foreign key
  answer_letter text,
  content text,

  CONSTRAINT answers_pkey PRIMARY KEY (problem_id, answer_letter) …
Run Code Online (Sandbox Code Playgroud)

postgresql database-design

5
推荐指数
1
解决办法
1729
查看次数

标签 统计

database-design ×1

postgresql ×1