0

Recently I have been working with a SQL Server database and I was trying to create some triggers for some tables using SQuirreL SQL Client and for some reason I was unable to get rid of the following pesky error message:

"Error: 'CREATE TRIGGER' must be the first statement in a query batch. SQLState: S0001 ErrorCode: 111"

The query I was attempting to execute was the following (I started out with a really simple trigger to make sure the syntax was correct):

CREATE TRIGGER meeting_overlap on adhoc_meeting
FOR INSERT
AS
DECLARE
    @myvar INT

When I attempted to execute my exact same query in Microsoft SQL Server Management Studio Express it executed fine. My question is: has anyone else run into similar problems using SQuirreL SQL Client and if so, what did you do to get rid of this error?

EDIT:

I am using SQuirrel SQL v2.6.8 with the Microsoft SQL Server JDBC Driver 2.0 and I am connecting to SQL Server 2005.

2
  • Not that this answers your question, but SQuirrel SQL is not nearly as good as Quest Toad (also has a freeware version) IMO. You may want to give it a crack to save the headache! toadsoft.com/toadsqlserver/toad_sqlserver.htm Commented May 28, 2009 at 4:43
  • Which version of SQuirreL? Which jdbc driver? Commented May 28, 2009 at 11:29

3 Answers 3

2

I was having the same problem. After some Googling, I found this article:

http://vsingleton.blogspot.com/2009/04/error-create-view-must-be-first.html

In short, wrap exec('') around your create trigger statement. In addition, any single quotes (') you have in the trigger statement need to be changed double single quotes ('').

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. Thank you very much for your answer and the precise summary (it worked just like you said).
0

Usually you get that error when attempting to run multiple statements in the same batch that are not allowed to be anything but the first statement in a batch. You may need a GO in between them. GO is not a SQL command but really a directive to the client tool to separate batches of commands.

2 Comments

I read about that when I first received the described error message, but as the query I was trying to execute was literally just that query I posted above, shouldn't it execute fine as the CREATE TRIGGER statement is the first (and only) statement in the batch?
I think SQuirrelSQL is putting something else in the batch first. Use the SQL Profiler to see what it's actually sending. And then see if you can disable that in SQuirrel SQL or submit a bug report.
0

I couldn't replicate this on SQuirrel SQL v2.6.8 using v1.2.2 of the jTDS jbdc driver against SQL 2005 SP3 (developer edition).

1 Comment

Interesting. I am also using SQuirrel SQL v2.6.8 and SQL Server 2005, but instead of the driver you mentioned I am using the Microsoft SQL Server JDBC Driver 2.0. Maybe the driver is to blame?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.