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
有人能帮我一个忙吗?
由于提前, 阿图尔
如果你想让人们帮助你,那么你应该接受他们给你的答案。它可以帮助那些在网站上搜索的人快速找到他们问题的最佳答案,这是人们在这里免费回答问题的小小认识。 –
我想我错过了一些东西。它看起来像你根本不需要触发器。为什么不能只将fail_percentage定义为计算列? – EBarr
汤姆H.是的,但我没有拒绝任何...我做错了什么? – Artur