使用 SQuirreL SQL 客户端创建 SQL Server 触发器的问题

发布于 2024-07-23 10:14:19 字数 569 浏览 9 评论 0原文

最近,我一直在使用 SQL Server 数据库,并尝试使用 SQuirreL SQL 客户端为某些表创建一些触发器,由于某种原因,我无法摆脱以下讨厌的错误消息:

“错误:‘CREATE TRIGGER’必须是查询批中的第一个语句。 SQL状态:S0001 错误代码:111“

我尝试执行的查询如下(我从一个非常简单的触发器开始,以确保语法正确):

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

当我尝试在 Microsoft SQL Server Management Studio Express 中执行完全相同的查询时,它执行了好的,我的问题是:是否有其他人在使用 SQuirreL SQL 客户端时遇到类似的问题,如果是,您采取了什么措施来消除此错误?

编辑:

我正在将 SQuirrel SQL v2.6.8 与 Microsoft SQL Server JDBC Driver 2.0 一起使用。我正在连接到 SQL Server 2005。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初见你 2024-07-30 10:14:19

我也遇到了同样的问题。 经过一番谷歌搜索后,我发现了这篇文章:

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

简而言之,将 exec('') 包裹在创建触发器语句周围。 此外,触发器语句中的任何单引号 (') 都需要更改为双单引号 ('')。

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 ('').

攒一口袋星星 2024-07-30 10:14:19

通常,当尝试在同一批处理中运行多个语句时,您会收到该错误,这些语句只能是批处理中的第一个语句。 您可能需要在它们之间插入 GOGO 不是一个 SQL 命令,而是真正的指令< /a> 到客户端工具来分隔多批命令。

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.

身边 2024-07-30 10:14:19

我无法使用针对 SQL 的 jTDS jbdc 驱动程序 v1.2.2 在 SQuirrel SQL v2.6.8 上复制此内容2005 SP3(开发者版)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文