简体   繁体   English

在SQL中缓慢更改数据

[英]Slowly Changing Data in SQL

My question is regarding the best way to implement a case of slowly changing data in MS SQL Express 2014. 我的问题是有关在MS SQL Express 2014中实现缓慢更改数据的最佳方法。

The scenario is as follows: 场景如下:

An administrator makes and defines tests, which users take. 管理员进行并定义用户要参加的测试。 The administrator has one table called "Questions", which has all questions possible. 管理员有一个名为“问题”的表,其中包含所有可能的问题。

Another table called "Quiz" identifies 10 questions from the Questions table to define a Quiz. 另一个名为“测验”的表从“问题”表中标识了10个问题,以定义测验。

Another table called "Quiz Definition" identifies how each of the 10 questions in the Quizzes table should be formatted (Short answer, or paragraph response). 另一个名为“测验定义”的表标识了测验表中10个问题中的每个问题应如何设置格式(简短答案或段落响应)。

Another table called "Administration Configuration" basically assigns a Quiz to a Quiz definition, which then gets administered to a user. 另一个称为“管理配置”的表基本上将测验分配给测验定义,然后将其管理给用户。

The end user wishes to be able to change parameters in any of these tables over time. 最终用户希望能够随时间更改任何这些表中的参数。 So for example, an administrator may want to change a question from "How are you doing?" 因此,例如,管理员可能要更改“您最近好吗?”中的问题。 to "How are you doing today?". 到“你今天好吗?”。

My issue is, say I administer a test today where the question ID 1234 was "How are you doing?". 我的问题是,例如,我今天管理一个测试,问题ID 1234为“你好吗?”。 Tomorrow, I change the question, and the day after, I administer the test as "How are you doing today?". 明天,我改变问题,第二天,我以“你今天好吗?”的方式进行测试。 If I rely on purely relational look-ups to ask what question was asked to the user, I will see that question ID 1234 was asked. 如果我仅依靠关系查询来问给用户的问题是什么,我将看到被问到的ID为1234的问题。 But the first test subject was asked the first version of the question, while the second user was asked the second version. 但是第一个测试对象被问到问题的第一个版本,而第二个用户被问到了第二个版本。

My question is, given this case, what is the best technique to 1) allow the administrator to edit records in the database while 2) maintaining "point in time" data for the test results so I know exactly how each test was executed? 我的问题是,在这种情况下,哪种最佳方法是:1)允许管理员编辑数据库中的记录,而2)维护测试结果的“时间点”数据,以便我确切地知道每个测试是如何执行的? All I could come up with so far was maintaining a massive "test results" table that listed the question, question type, etc. in the same row as every result. 到目前为止,我所能做的就是维护一个庞大的“测试结果”表,该表在每个结果的同一行中列出问题,问题类型等。 The issue with that method is that there may be a lot of parameters to keep track of in the actual application, making the results table like 30 columns wide. 该方法的问题在于,在实际应用程序中可能需要跟踪许多参数,从而使结果表宽30列。

Make a new table (foo) which saves the history of questions revisions. 新建一个表(foo),以保存问题修订的历史记录。 foo table has ID, questionId and questionBody. foo表具有ID,questionId和questionBody。 Also in test results you should save foo.ID . 同样在测试结果中,您应该保存foo.ID。 No more changes needed in Quiz definition. 测验定义中无需更改。

You need to change the data model. 您需要更改数据模型。

A test is a test with a set of questions, and the questions have a history that grows with any change. 测试是带有一组问题的测试,并且问题的历史随着变化而增长。

So, your test will address the questions with a defined version (history id). 因此,您的测试将使用已定义的版本(历史ID)解决问题。 If you change the test, it will make sense, to give the test a history as well. 如果您更改测试,则也应该为测试提供历史记录。

Update: If you cannot change test and question, you could create a test-history table and a question-history table and testquestion history. 更新:如果您无法更改测试和问题,则可以创建一个测试历史记录表以及一个问题历史记录表和测试问题历史记录。 On changing the question, you duplicate the test, question, links into history table. 在更改问题时,您将测试,问题链接复制到历史表中。 Then modify the question and update the test histody. 然后修改问题并更新测试历史记录。 This is not very nice and will duplicate a lot of data. 这不是很好,并且会重复很多数据。 Also, xou will need special code to extract and handle display of historic test. 另外,xou将需要特殊的代码来提取和处理历史测试的显示。 It is better imho, to have a combined fk, made from id and version. 更好的恕我直言,有一个结合在一起的fk,由id和version组成。 when updating the question, you update the hist version of test, have an n:m table ready with test-question relation and duplicate the links to the questions. 更新问题时,您将更新测试的历史版本,准备一个具有test-question关系的n:m表,并复制问题的链接。 then update the single question by duplicating it, changing version and text creating a new version and link it to the new test, replacing the old version. 然后通过复制单个问题,更改版本和创建新版本的文本来更新单个问题,并将其链接到新测试,以替换旧版本。

The importance of question.id in your system is unknown. 在系统中question.id的重要性未知。 if it is not relevant, you need to version only test. 如果不相关,则只需进行版本测试。 A new version of a question then has no connection with the old version. 那么问题的新版本与旧版本无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM