0
我使用SQLServer的2005年设计了一个DAO运行插入SQL这样的:插入单表造成的僵局
INSERT INTO eventsources (recevied_event_time_stamp, recevied_event_curve_name, recevied_event_curve_value, recevied_event_quote_date, total_time_for_event_processing, number_of_published_events{0}, triggered_curve, recevied_event_day)
然而,该系统运行一段时间,这似乎是不可能给我后引发死锁异常,我认为只有在以相反顺序使用多个资源时才会发生死锁。
插入是多线程,这可能是一个问题?但我正在使用Spring.Net的AdoTemplate,它宣布它是线程安全的。
我已经创建的eventsources表
CREATE TRIGGER TRIGGER_EVENTSOURCES
ON eventsources
FOR INSERT
AS
DECLARE @newlyInertedFormulaName VARCHAR(100)
DECLARE @error_message varchar(10)
DECLARE @last_calculated_date datetime
DECLARE @timeframe datetime
DECLARE @publishedEvent int
SELECT @publishedEvent = (SELECT number_of_published_events FROM Inserted)
SELECT @newlyInertedFormulaName = (SELECT triggered_curve FROM Inserted)
SELECT @error_message = (SELECT error_message FROM Inserted)
SELECT @last_calculated_date = (SELECT recevied_event_time_stamp FROM Inserted)
if @publishedEvent > 0
BEGIN
update formulaversions set last_calculated_date = @last_calculated_date where
formulaname = @newlyInertedFormulaNam
e and lifecycle = 3;
END
if @error_message is not NULL
BEGIN
update formulaversions set status = 2 where formulaname = @newlyInertedFormulaName and lifecycle = 3;
END
ELSE
update formulaversions set status = 1 where formulaname = @newlyInertedFormulaName and lifecycle = 3 and (status <>
2 or status is null);
GO
是否有使用这个触发的任何问题的扳机?
任何意见将不胜感激。
formulaversions上是否有触发器? – 2010-10-14 11:29:08
(1)如果存在多行插入,则触发器将失败(尽管如此,与死锁问题无关)。 (2)您应该使用SQL Profiler来捕获死锁图。 (3)这两个表('formulaversions'和'eventsources')有哪些外键? – 2010-10-14 11:30:44
打开服务器上的跟踪标志1204或1222,您应该了解哪些资源涉及到死锁。 http://msdn.microsoft.com/en-us/library/ms188396.aspx – 2010-10-14 11:53:48