2013-03-27 283 views
-1

我在表上創建了一個觸發器,現在我無法更改或刪除它。 我甚至不能訪問表。 我該怎麼辦?無法刪除觸發器

觸發腳本:

create trigger [Products].[InsertLessThen5InStock] 
on [Products].[Products] 
after update 
as 
BEGIN 
    DECLARE @ck int 

      select UnitsInStock from Products.Products where UnitsInStock<5 
    set @[email protected]@ROWCOUNT 
    print @ck 
    if @ck >0 
    BEGIN 
     DECLARE @mails varchar (200) 
     exec dbo.Manager_email @mails output 
     EXEC msdb.dbo.sp_send_dbmail 
     @profile_name =    'DefaultMailSender', 
     @recipients =    @mails , 
     @body =      'Products that will expire in less then 5 days', 
     @subject =     'Products that will expire in less then 5 days', 
     @body_format =    'HTML', 
     @query =     'EXECUTE MadCat.dbo.SaveTableAsHTML 
           @DBFetch =''select UnitsInStock from Products.Products where UnitsInStock<5''' 

    END 
END 
GO 
+1

爲什麼你不能改變它或刪除它? – PowerUser 2013-03-27 18:42:02

+2

你運行哪些腳本來嘗試刪除或修改它?你得到什麼錯誤? 「我甚至不能訪問表格」是什麼意思?你需要更多地瞭解你的問題,以及你所嘗試過的。 – LittleBobbyTables 2013-03-27 18:42:39

+0

我試圖刪除它拋出gui並放下觸發器... – DnL 2013-03-27 18:43:18

回答

2

由於它抱怨不能夠得到鎖定,這意味着一些進程已經專門預留表中。您應該嘗試重新啓動服務器,然後發出drop trigger命令。

drop trigger [Products].[InsertLessThen5InStock] 
+0

是的,我試過了,它不工作 – DnL 2013-03-27 18:52:25

+0

如果它手動放下它劑量顯示沒有任何想法但當我試圖刪除它使用GUI它說:「超過鎖定請求超時期限」 我不得不說這對於一個學校項目,所以我只有這個db – DnL 2013-03-27 19:01:01

+0

沒有別的工作正在這邊工作,我關閉了一切。 我通過任務管理器關閉sql,然後處理並結束進程樹。 我甚至不能在表上選擇 – DnL 2013-03-27 19:12:37