Sybase:“go”附近的语法不正确在“如果存在”中堵塞
这是我的 sql 语句,
IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE')
drop table dbo.PNL_VALUE_ESTIMATE
go
isql 会显示此错误消息
Msg 102, Level 15, State 1:
Server 'DB_SERVER', Line 3:
Incorrect syntax near 'go'.
,但该 sql 语句对我来说看起来是正确的。怎么了?
Sybase版本为15
This is my sql statement
IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE')
drop table dbo.PNL_VALUE_ESTIMATE
go
isql bails out with this error message
Msg 102, Level 15, State 1:
Server 'DB_SERVER', Line 3:
Incorrect syntax near 'go'.
But the sql statement look correct to me. What's wrong?
Sybase version is 15
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
或者这个:
或者这个:
有效果吗?
Try this:
or this:
or this:
Does any work?
GO
不是T-SQL的关键字,而是编辑器的关键字。SMSS(以及其他)将其用作发送到数据库服务器的命令批次之间的“划分”。在存储过程甚至脚本文件中执行它是行不通的。
编辑:也许它适用于 SyBase,但我认为在这种情况下它需要大写。
GO
is not a keyword of T-SQL, but of the editor.SMSS (between others) uses it as 'division' between batches of commands it sends to the database server. Executing it inside a stored procedure, or even a script file, won't work.
edit: Maybe it works with SyBase, but I think it'll need to be uppercase in that case.
从文档中可以看出,
GO
语句是您正在使用的编辑器的命令,而不是SQL
本身:也就是说,Sybase 也是一个支持 GO 语句的编辑器。
我也遇到过同样的问题,但是是使用 SQL Management Studio。问题是编辑器不支持某些语句周围的混合换行符类型 -
GO
就是其中之一。例如,在 Management Studio 中,只允许 Windows 风格的换行符 (CR + LF),如果我使用 Linux 格式 (LF),它将给出与上面完全相同的错误。Notepad++(我使用的)等文本编辑器可以选择默认使用的行尾字符类型(Windows、Linux、Mac (CR))。
尝试检查语句中使用了哪些换行符,看看是否可以解决问题。
From the documentation, the
GO
statement is a command of the editor you're using, notSQL
itself:That said - Sybase is also an editor that supports the
GO
statement.I've had the same problem, but with SQL Management Studio. The issue is that the editor does not support mixed-newline types around certain statements -
GO
being one of them. In Management Studio, for example, only Windows-style newlines (CR + LF) are allowed and if I were to use the Linux format (LF), it will give the exact same error as yours above.Text-editors such as Notepad++ (what I use) have an option for what type of End-of-Line characters you use by default (Windows, Linux, Mac (CR)).
Try checking what newline character(s) are being used in your statements to see if that can fix the problem.
对象引用不应该有
dbo..PNL_VALUE_ESTIMATE
因为您没有给出数据库名称,并且如果您包含 obj 所有者,则需要 .. 错过数据库名称?
我也会在 true 部分中执行:
EXEC('DROP TABLE dbo..PNL_VALUE_ESTIMATE')
,因为 DROP TABLE 始终会被编译,如果表不存在,您仍然会失败。
你还需要dbo吗?如果您的 sql 始终以 dbo 身份运行,则将其省略。
Shouldn't the object reference have
dbo..PNL_VALUE_ESTIMATE
because you haven't given a database name, and if you include the obj owner you need .. to miss the db name?
I'd go:
EXEC('DROP TABLE dbo..PNL_VALUE_ESTIMATE')
in the true part as well, because DROP TABLE is always compiled, and if the table isn't there you'll still have a failure.
Do you even need dbo? If your sql always runs as dbo just leave it out.