CREATE TRIGGER must be the first statement in a batch
sql-server, t-sql, triggers
Solution
The error message "'CREATE TRIGGER' must be the first statement in a query batch." usually occurs when a preceding group (batch) of statements does not have a terminating `GO`
So, I would suggest adding add a `GO` to the end of the preceding batch's statements.
Problem
I have the below 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 ``` I'm getting an error msg saying: 'CREATE TRIGGER' must be the first statement in a query batch.