SQL SERVER – Get Column Names

A very common question, I keep on getting is how to get column names for a particular column. Well, it is pretty straightforward and easy to do. Let us see various methods to do it.

Method 1:

SELECT * 
FROM sys.columns 
WHERE object_id = OBJECT_ID('TableName')

Method 2:

SELECT * 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_NAME = N'TableName'

Method 3:

SELECT  SCHEMA_NAME(o.schema_id) SchemaName, o.Name, c.Name
FROM     sys.columns c 
         JOIN sys.objects o ON o.object_id = c.object_id 
WHERE    o.type = 'U' AND c.name = N'TableName'
ORDER BY o.Name, c.Name

Method 4:

sp_help N'TableName'

Well, that’s it for today. Let me know what are your thoughts about this blog post. Let me know if you want me to create a video on this topic. I hope you like this blog post about how to Get Column Names of Table.

Here are my few recent videos and I would like to know what is your feedback about them. You can subscribe to my youtube channel here. Recently I have written a book about blogging. The name of the book is How to Become Successful Blogger and it is available to download via Kindle eBook over here. Let me know what you think about it.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Menu
Exit mobile version