Execute ms sql server queries from linux terminal

7.2k views Asked by At

I need to query a MS SQL Server database from a linux terminal. Searching the web and this site I found freetds and then sqsh. I have installed them and seems to connect to the server but I can't get it to execute a query, I'm definitely doing something wrong.

I have configure freetds as:

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

The databse server is a Sql Server 2008 r2.

When connecting I use the following command:

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

Which gives me a prompt like:

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>

Then I try to enter a query like:

1> select * from C_PROPS;

But nothing happens. What am I doing wrong?, just need simple selects and updates.

1

There are 1 answers

1
knb On BEST ANSWER

I think that the semicolon_hack variable is not set.

You need to write your command like this

select * from C_PROPS
go

or, at the beginning of a sqsh session

\set semicolon_hack=on
go

now you can do

select * from C_PROPS;

or, alternatively, create a .sqshrc in your home directory and insert this snippet

#
# $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