I would like to query the name of all columns of a table. I found how to do this in:
But I need to know: how can this be done in Microsoft SQL Server (2008 in my case)?
I would like to query the name of all columns of a table. I found how to do this in:
But I need to know: how can this be done in Microsoft SQL Server (2008 in my case)?
This is better than getting from
sys.columns
because it showsDATA_TYPE
directly.Summarizing the Answers
I can see many different answers and ways to do this but there is the rub in this and that is the
objective
.Yes, the objective. If you want to
only know
the column names you can useBut if you want to
use
those columns somewhere or simply saymanipulate
them then the quick queries above are not going to be of any use. You need to useone more way to know some specific columns where we are in need of some similar columns
You can obtain this information and much, much more by querying the Information Schema views.
This sample query:
Can be made over all these DB objects:
you can use this query
Simple and doesnt require any sys tables