How To Display Only Column Names SQL Query

I have a scenario where I want to just display the column names and not the data at all.

So I started to dig into my memory where I remember achieving this task using INFORMATION_SCHEMA.COLUMNS

I also started to find some interesting solutions googling a bit. I should agree Bing wasn’t able to get to my results. But I would still recommend Bing as it has some really eye catching features compared to Google. So let’s get back to our job of achieving what we need using SQL query.

Below are three ways through which I was successfully able to achieve this task for a table named “Article”

1) Logical Way – Not sure how effective this is though

SELECT * FROM Article WHERE (1 = 0)

2) Most recommended way to get what exactly you need

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ‘Article’

3) Another logical way which is pretty interesting
SELECT TOP 0 * FROM Article

So Now I know i don’t have to bing again for getting this task done in future. That’s the reason I am blogging this so that you people can also recommend others to use my blog to get this task done pretty quick.

Advertisements