A very common question, I keep on getting is how to get column names for a particular tables. Well, it is pretty straightforward and easy to do. Let us see various methods to do it.
SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('TableName')
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'TableName'
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
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.
- Forwarded Records and Performance – SQL in Sixty Seconds #155
- Hide Code in SSMS – SQL in Sixty Seconds #154
- Zoom in SSMS – SQL in Sixty Seconds #153
- Transfer Schema of Table – SQL in Sixty Seconds #152
- Find a Table in Execution Plan – SQL in Sixty Seconds #151
Reference: Pinal Dave (https://blog.sqlauthority.com)