1

我不是 SQL 程序员,但我在项目中遇到了障碍,必须构造一个触发器,该触发器将在插入命令后触发。问题如下:

我有 3 张桌子:

dbo. Build

id   (PK, int, not null)
date (smalldatetime, not null)


dbo.TestCase

id   (PK, int, not null)
Name (nvarchar(200), not null)


dbo.TestCaseExecution

id              (PK, int, not null)
build_id        (FK, int, not null)
testcase_id     (FK, int, not null)
passed          (int, null)            //1 or 0
executed        (int, null)            //1 or 0
duration        (real, null)
fail_percentage (real, null)           //null

现在,我从 .xml 文件中读取数据,并通过用 C# 编写的项目将数据添加到数据库中。每次构建后,我必须根据“通过”和“执行”值更新数据库并计算每个测试的 fail_percentage。

fail_percentage = (100)*(1 - (PassNumber/ExecutionNumber))

所以我需要一个触发器,它将: 1. 在插入命令后触发 2. 根据早期值计算 fail_percentage,例如

after reading from file:

id  build_id  testcase_id  passed  executed  duration  fail_percentage
1   1         001          1       1         12:09     null

after trigger:

id  build_id  testcase_id  passed  executed  duration  fail_percentage
1   1         001          1       1         12:09     0

after reading from file:
id  build_id  testcase_id  passed  executed  duration  fail_percentage
1   1         001          1       1         12:09     0
2   2         001          0       1         12:32     null

after trigger:
id  build_id  testcase_id  passed  executed  duration  fail_percentage
1   1         001          1       1         12:09     0
2   2         001          0       1         12:32     50

谁能帮帮我?

在此先感谢,阿图尔

4

1 回答 1

0

我没有使用触发器就做到了,在我的应用程序中,我将所有需要的数据存储在字典中:

  • 测试名称作为键值
  • 将值和执行值作为值传递

然后我计算百分比并将其插入数据库。

于 2011-08-04T11:36:54.177 回答