2011-08-03 37 views
1

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

我有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 

有人能帮我一个忙吗?

由于提前, 阿图尔

+1

如果你想让人们帮助你,那么你应该接受他们给你的答案。它可以帮助那些在网站上搜索的人快速找到他们问题的最佳答案,这是人们在这里免费回答问题的小小认识。 –

+1

我想我错过了一些东西。它看起来像你根本不需要触发器。为什么不能只将fail_percentage定义为计算列? – EBarr

+0

汤姆H.是的,但我没有拒绝任何...我做错了什么? – Artur

回答

0

确定

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

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

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