我在SQL Server 2000中的表的觸發器,這是觸發:SQL Server 2000的奇數插入觸發器行爲 - 遞歸像
ALTER Trigger [dbo].[Set_Asignado_State] ON [dbo].[Tables]
FOR INSERT AS
BEGIN
DECLARE @area varchar(1)
SELECT @area = Table_Area_ID FROM inserted
IF (@area = 'L')
BEGIN
INSERT INTO Table_History
SELECT (SELECT TOP 1 Table_Area_Id AS Table_Area_Id FROM inserted) AS Table_Area_Id,
(SELECT SUBSTRING(CAST(YEAR(GETDATE()) AS VARCHAR), 3, 2)) AS Table_Year,
(SELECT TOP 1 Table_Seq AS Table_Seq FROM inserted) AS Table_Seq,
(SELECT TOP 1 ID FROM Table_Status WHERE Description = 'Asignado') AS Status,
'' AS Responsible,
(SELECT TOP 1 OrigDept FROM inserted) AS User_Responsible,
GETDATE() AS [DateTime],
'None' AS Comments
FROM Tables
WHERE Tables.Table_Area_Id = (SELECT TOP 1 Table_Area_Id AS Table_Area_Id FROM inserted) AND
Tables.Table_Year = (SELECT SUBSTRING(CAST(YEAR(GETDATE()) AS VARCHAR), 3, 2))
IF @@ERROR <> 0
BEGIN
DECLARE @errorMsg NVARCHAR(256)
SET @errorMsg = @@ERROR;
PRINT 'Error Inserting in Table_History'
END
END
END
現在,當他們插入「表」的記錄,觸發器被調用,但它會在Table_History上插入許多記錄。
我跟我的同事聊過,似乎沒有錯! = S有關此的任何線索?難道我做錯了什麼?
在此先感謝=)
@Hugo:或許你可以用文字解釋它應該做什麼? – 2009-03-05 03:31:23
用剪刀跑... – dkretz 2009-03-05 04:22:19