November 23rd, 2005

Simple column name list in sybase with sqsh

At my current job, we primarily use Sybase ASE for our database servers. For most of my querying needs, I use a nice little tool called sqsh, a handy replacement for the basic Sybase ‘isql’.

I hate the excessive amounts of output that sybase gives me when I do ‘sp_help [table_name]‘, because most of the time all I’m trying to do is get a list of column names for a particular table.

MySql’s ’show databases’, ’show tables’, ’show columns’, etc. seem so much more intuitive to me.

So, a couple days ago I chained together a few tools, and created an alias + function combo that let me simply type ‘show_columns [table_name]‘, and get nothing but a quick list of column names.

Here is what I added to my .sqshrc file to make this a permanent addition to my collection of useful commands

\func show_columns_func
\echo Column list for table: ${1}
sp_help ${1}; -m vert grep “Column_name:” \sed -e ’s/Column_name: *\([^ ]\)/\1/g’
\done
\alias show_columns=”\call show_columns_func ”