I have installed SQL Server 2017 on RHEL Linux 7.3, and using SQLCMD utility for querying the SQL Server.

When I try to query for example: 'SELECT * FROM SYS.DATABASES'. I get output like the following:

enter image description here

How to format the output for SQL commands on SQLCMD for SQL Server on RHEL Linux?

For example, in Oracle we use 'SET LINES 200 PAGES 200' to format the output / width of the output columns.

Note: I have already tried the following workaround (as per other answer on dba.stackexchange):

C:/> sqlcmd -S my_server :setvar SQLCMDMAXVARTYPEWIDTH 30 :setvar SQLCMDMAXFIXEDTYPEWIDTH 30 SELECT * from my_table GO

  • Thanks @DanGuzman, I installed the mssql-cli and its working fine.Still have to learn it and get used to it though! (shifting from ssms)
    – SSS
    Feb 27 '19 at 5:15
  • Glad to hear mssql-cli is working well for you. I elaborated on my comment with an answer.
    – Dan Guzman
    Feb 27 '19 at 10:57

The sqlcmd utility is handy for executing T-SQL scripts via command-line, such as in automation scenarios, but is limited in its output formatting capabilities and interactive query editor.

Consider using mssql-cli instead for interactive terminal queries. This open source tool provides pagination, handles wide results well, includes IntelliSense ,and allows one to use emacs or vi mode. mssql-cli runs on Linux, Windows, and Mac.

enter image description here

I'll add that Azure Data Studio is a cross-platform alternative to SSMS when a full desktop experience is desired. It does not include all features available in SSMS but does include other features and provides greater extensibility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.