2012-11-13 81 views
8

我有以下觸發:CREATE TRIGGER必須是第一條語句批處理

CREATE Trigger enroll_limit on Enrollments 
Instead of Insert 
As 
Declare @Count int 
Declare @Capacity int 
Select @Count = COUNT(*) From Enrollments 
Select @Capacity = Capacity From CourseSections 
If @Count < @Capacity 
Begin 
     Insert Into Enrollments Select * From Inserted 
End 
GO 

我發現了一個錯誤味精說:

「CREATE TRIGGER」必須首先聲明在查詢批處理中。

+0

可能的重複:http://stackoverflow.com/questions/10336384/dynamic-sql-error-create-trigger-must-be-the-first-statement-in-a-query-batch – WholeLifeLearner

回答

29

錯誤消息「'CREATE TRIGGER'必須是查詢批處理中的第一條語句。」通常發生在前面的語句組(批)沒有終止時GO

所以,我建議在前面的批處理語句的末尾添加一個GO

+1

值得注意「GO」需要在自己的路線上。 (我發現了困難的方式) –

相關問題