我可以调试/监视触发器的INSERTED和DELETED记录/值吗? [英] Can i debug/watch on the trigger's INSERTED and DELETED records/values?

查看:186
本文介绍了我可以调试/监视触发器的INSERTED和DELETED记录/值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调试一个触发器时,是否可以在INSERTED或DELETED上添加一个WATCH




我想不是,至少我不能'找不到这样做的方法。

有人对我如何看待价值观有什么建议吗?


我确实试过做类似的事情


INSERT INTO TABLE1(NAME)

从插入中选择名称


但这不起作用。当触发器完成并且我看到了TABLE1时,它没有记录。


是否有任何文件,描述方式的网络链接

调试触发器'INSERTED和DELETED?


谢谢

解决方案

2006年1月25日星期三13:29:59 -0500,serge写道:

当我调试一个触发器时,可以添加一个WATCH
插入还是删除?


嗨Serge,


No.在调试过程中,(很遗憾)无法看到

任何表格的内容。

我认为不是,至少我不知道这样做的方法。
是否有人建议我如何看待价值观?


您可以在触发器代码中添加SELECT,然后从
查询分析器中测试您的代码。插入和删除的伪表格

中的值将转到查询分析器结果窗格。


或者您可以使用SELECT INTO或INSERT ...选择将值存储在

a持续表中。

我确实尝试过像

INSERT INTO TABLE1(NAME)
从插入中选择名称

但这不起作用。当触发器完成并且我看到TABLE1时,其中没有记录。


嘿,这就是我的建议! < g>


这应该有效。为什么它不适合你的一些潜在原因

是:

- 也许代码从未达到插入声明?这个

可能是这样的情况,如果表TABLE1没有;在触发

执行后根本不存在。

- 你检查了表吗?在触发

执行之前,TABLE1不存在?如果是这样,上面的命令将导致错误(并且

你应该得到一条错误消息)。

- 你是否用零行运行触发器操作? (即更新或

DELETE,或者影响0行的INSERT .. SELECT)

- 不要使用临时表。当触发器执行完毕时它将被删除,因为它只存在于触发器的范围内。

- 在DELETTE触发器中,插入的表总是为空。


以上所有都是猜测,当然。我必须看到实际的

代码来帮助你进一步。

是否有任何文档,网页链接描述调试触发器的方式'插入并删除了吗?

谢谢



-

Hugo Kornelis,SQL Server MVP


serge(se****@nospam.ehmail.com)写道:

当我调试一个触发器时,可以添加一个WATCH
INSERTED或DELETED?

我想不是,至少我不知道这样做的方法。
是否有人建议我如何看待价值?

我确实试过做类似的事情

INSERT INTO TABLE1(NAME)
从INSERTED中选择名称

但是这并没有工作。当触发器完成并且我看到TABLE1时,其中没有记录。




除了Hugo的建议,请继续请注意,如果触发器

失败,则该语句将被回滚,并且包括插入表1的

数据

-

Erland Sommarskog,SQL Server MVP, es****@sommarskog.se


SQL Server 2005联机丛书
http://www.microsoft.com/technet/pro...ads/books.mspx

SQL Server 2000联机丛书 http://www.microsoft.com/sql/prodinf ... ons / books.mspx


2006年1月25日星期三22:27:44 +0000(UTC),Erland Sommarskog写道:
serge(se****@nospam.ehmail.com)写道:

当我调试一个触发器时,可以在INSERTED上添加一个WATCH
或者删除了?

我想不是,至少我不知道这样做的方法。
是否有人建议我如何看待这些价值观?

我确实尝试过像

INSERT INTO TABLE1(NAME)
从插入选择名称

但这没有用。当触发器完成并且我看到TABLE1时,其中没有记录。



除了Hugo的建议,请记住,如果触发器
失败,然后声明将被回滚,并且包括插入表1的
数据




啊,当然。我怎么能忘记它?


睡觉的时间,我想:-)


谢谢,Erland!

-

Hugo Kornelis,SQL Server MVP


When i debug a trigger is it possible to add a WATCH
on the INSERTED or DELETED?

I think not, at least I couldn''t figure out a way to do so.
Does someone have a suggestion on how I can see the values?

I did try to do something like

INSERT INTO TABLE1(NAME)
SELECT NAME FROM INSERTED

but this didn''t work. When the trigger completed and I
went to see the TABLE1, there were no records in it.

Are there any documents, web links that describe ways
of debugging the trigger''s INSERTED and DELETED?

Thank you

解决方案

On Wed, 25 Jan 2006 13:29:59 -0500, serge wrote:

When i debug a trigger is it possible to add a WATCH
on the INSERTED or DELETED?
Hi Serge,

No. During debugging, it is (unfortunately) not possible to see the
contents of ANY tables.

I think not, at least I couldn''t figure out a way to do so.
Does someone have a suggestion on how I can see the values?
You could add a SELECT to the trigger code, then test your code from
Query Analyzer. The values in the inserted and deleted pseudo-table
would go to the Query Analyzer results pane.

Or you could use SELECT INTO or INSERT ... SELECT to store the values in
a persistant table.

I did try to do something like

INSERT INTO TABLE1(NAME)
SELECT NAME FROM INSERTED

but this didn''t work. When the trigger completed and I
went to see the TABLE1, there were no records in it.
Hey, that''s just what I suggested! <g>

This should work. Some potential reasons for why it didn''t work for you
are:
- Maybe the code never even reached the insert into statement? This
might be the case if the table TABLE1 didn;t exist at all after trigger
execution.
- Did you check that the table TABLE1 did not exist before the trigger
was executed? If it did, the command above would result in an error (and
you should have gotten an error message).
- Did you run the trigger with a zero-row operation? (I.e. an UPDATE or
DELETE, or an INSERT .. SELECT that affected 0 rows)
- Don''t use a temp table for this. It will be removed when the trigger
execution finishes, as it only exists in the scope of the trigger.
- In a DELETTE trigger, the inserted table is ALWAYS empty.

All the above are just guesses, of course. I''d have to see the actual
code to help you further.

Are there any documents, web links that describe ways
of debugging the trigger''s INSERTED and DELETED?

Thank you


--
Hugo Kornelis, SQL Server MVP


serge (se****@nospam.ehmail.com) writes:

When i debug a trigger is it possible to add a WATCH
on the INSERTED or DELETED?

I think not, at least I couldn''t figure out a way to do so.
Does someone have a suggestion on how I can see the values?

I did try to do something like

INSERT INTO TABLE1(NAME)
SELECT NAME FROM INSERTED

but this didn''t work. When the trigger completed and I
went to see the TABLE1, there were no records in it.



In additions to Hugo''s suggestions, keep in mind that if the trigger
fails, then the statement will be rolled back, and that includs the
data insertedvinto Table1
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


On Wed, 25 Jan 2006 22:27:44 +0000 (UTC), Erland Sommarskog wrote:

serge (se****@nospam.ehmail.com) writes:

When i debug a trigger is it possible to add a WATCH
on the INSERTED or DELETED?

I think not, at least I couldn''t figure out a way to do so.
Does someone have a suggestion on how I can see the values?

I did try to do something like

INSERT INTO TABLE1(NAME)
SELECT NAME FROM INSERTED

but this didn''t work. When the trigger completed and I
went to see the TABLE1, there were no records in it.



In additions to Hugo''s suggestions, keep in mind that if the trigger
fails, then the statement will be rolled back, and that includs the
data insertedvinto Table1



Ah, of course. How could I forget it?

Time for bed, I guess :-)

Thanks, Erland!

--
Hugo Kornelis, SQL Server MVP


这篇关于我可以调试/监视触发器的INSERTED和DELETED记录/值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆