从linux终端执行ms sql server查询

时间:2014-01-27 10:35:54

标签: freetds sqsh

我需要从linux终端查询MS SQL Server数据库。搜索网站和这个网站我找到了freetds,然后是sqsh。我已经安装了它们,似乎连接到服务器但我无法让它执行查询,我肯定做错了。

我将freetds配置为:

[MSSql]
        host = 192.168.1.4
        port = 1433
        tds version = 7.0

数据库服务器是Sql Server 2008 r2。

连接时我使用以下命令:

sqsh -S MSSql -U sa -P sa -D databasename

这给了我一个提示:

sqsh-2.1.7 Copyright (C) 1995-2001 Scott C. Gray
Portions Copyright (C) 2004-2010 Michael Peppler
This is free software with ABSOLUTELY NO WARRANTY
For more information type '\warranty'
1>

然后我尝试输入如下的查询:

1> select * from C_PROPS;

但没有任何反应。我做错了什么?只需要简单的选择和更新。

1 个答案:

答案 0 :(得分:5)

我认为semicolon_hack变量未设置。

您需要像这样编写命令

select * from C_PROPS
go

或者,在sqsh会话开始时

\set semicolon_hack=on
go

现在你可以做到

select * from C_PROPS;

或者,在您的主目录中创建.sqshrc并插入此代码段

#
# $semicolon_hack : This turns on the ability to use a semicolon as
#             a sort of in-line go.  It is kind of hacky but seems
#             to work pretty well.
#
\set semicolon_hack=on
相关问题