How to list column headers of a SQL Server table using sp_help perhaps?
Posted
by Hamish Grubijan
on Stack Overflow
See other posts from Stack Overflow
or by Hamish Grubijan
Published on 2010-03-29T21:04:20Z
Indexed on
2010/03/29
21:13 UTC
Read the original article
Hit count: 870
sql-server-2008
|sp-help-operator
Hi,
I have a few tables with 70-80 columns in them. I would like to populate them with somewhat random data, unless I will not be able to do so due to key violation, etc.
The first step would be simply to get the list of all headers. There seem to be two ways:
A) Run select * from table_of_interest;
in MSFT SQL Server Management Studio 2008. Now, right-click the result and click "Copy With headers". However, I get zero rows back, and when I try to copy nothing + headers, I get:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Value cannot be null.
Parameter name: data (System.Windows.Forms)
------------------------------
BUTTONS:
OK
------------------------------
This looks like a bug ... anyhow ... there is another way.
B) I can run sp_help table_of_interest;
. However, I end up getting too much back. I get 7 different tables back but I am only interested in the second one. The columns of the second table are:
Column_name | Type | Computed | Length | Prec | Scale | Nullable |
TrimTrailingBlanks | FixedLenNullInSource | Collation
I might be interested in just a Column_name
and Type
, but maybe other columns.
So ... since sp_help probably runs a bunch of queries ... how do I get under the hood? How can I run the second query AND filter down the number of columns that I am interested in?
Many Thanks!
© Stack Overflow or respective owner