2011-11-10 29 views
1

命令:SQL Server將無法在表上創建觸發器我可以查詢

select * from dbo.hmg_cahplots 

返回9250行。然而,當我嘗試創建一個觸發器,它失敗:

消息8197,級別16,狀態6,過程LotUpdateTrigger_tdp,1號線 對象「dbo.hmg_cahplots」不存在,或者是這個無效 操作。

觸發代碼:

CREATE TRIGGER dbo.LotUpdateTrigger_tdp ON dbo.hmg_cahplots FOR UPDATE, INSERT 
AS 
BEGIN 
    update lot 
    set lot.hmg_planmodelname = model.hmg_modelname, lot.hmg_thermslotincentive = model.hmg_thermsincentive, 
     lot.hmg_thermslotincentive_base = model.hmg_thermsincentive_base, lot.hmg_kwlotincentive = model.hmg_kwincentive 
    from hmg_cahplots as lot inner join i 
      on lot.hmg_cahplotsid = i.hmg_cahplotsid 
     inner join hmg_pgecahp as proj 
      on proj.hmg_pgecahpid = lot.hmg_pgecahplots 
     left outer join hmg_pgecahpmodels as model 
      on model.hmg_pgecahpmodelsid = lot.hmg_cahpplanstolotsid 
      and model.hmg_pgecahpplansid = lot.hmg_pgecahplots   
END 

我懷疑這是很難解決的。我假設我需要指定一個名稱空間或其他東西。但是,我是SQL Server的新手,我不知道如何開始。

感謝蒂姆 -

回答

7
  1. 你確定你位於正確的數據庫,不掌握?
  2. 你確定你的權限沒問題嗎?
  3. 你確定這是一張桌子,而不是一個視圖?
+0

我要求我們的管理員檢查#2。我正在使用MS SQL Server Management Studio Express。我會檢查文檔並試圖弄清楚我是如何知道我是否在正確的數據庫中,而不是主數據庫。有一個模式表我可以查詢,看看這是一個表或視圖? –

+1

好的...它看起來像我試圖把觸發器放在視圖上。我給出的DB圖是錯誤的......這解釋了這個謎。感謝您的幫助整理出來。 –

2

如果確定該表存在,你正試圖創建在同一個數據庫觸發器,那麼就from之前和之後lot.hmg_kwlotincentive = model.hmg_kwincentive,刪除昏迷。