{"id":1805,"date":"2013-05-30T02:35:39","date_gmt":"2013-05-30T02:35:39","guid":{"rendered":"http:\/\/www.withdata.com\/ad\/?p=1805"},"modified":"2017-04-20T10:49:59","modified_gmt":"2017-04-20T10:49:59","slug":"how-to-get-column-names-from-sql-server-table","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/sql-server\/how-to-get-column-names-from-sql-server-table.html","title":{"rendered":"How to get column names from Sql Server table"},"content":{"rendered":"<p>SELECT [name] AS [Column Name] FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE type = &#8216;U&#8217; AND [Name] = &#8216;My_Table_Name&#8217;)<\/p>\n<p>Type = &#8216;V&#8217; for views Type = &#8216;U&#8217; for tables<\/p>\n<p>For SQL Server 2008, we can use <strong>information_schema.columns<\/strong> for getting column information:<\/p>\n<p>SELECT * FROM information_schema.columns WHERE table_name = &#8216;My_Table_Name&#8217; ORDER BY ordinal_position<\/p>\n<p>See also:<\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/db2\/how-to-get-column-names-from-db2-table.html\">How to get column names from DB2 table<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/oracle\/how-to-get-column-names-from-oracle-table.html\">How to get column names from Oracle table<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/mysql\/how-to-get-column-names-from-mysql-table.html\">How to get column names from Mysql table<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/postgresql\/how-to-get-column-names-from-postgresql-table.html\">How to get column names from PostgreSQL table<\/a><\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/sqlite\/how-to-get-column-names-from-sqlite-table.html\">How to get column names from SQLite table<\/a><\/p>\n<p>Some SQL Server tools you can try: <a href=\"https:\/\/www.withdata.com\/sql-server\/\"> https:\/\/www.withdata.com\/sql-server\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SELECT [name] AS [Column Name] FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE type = &#8216;U&#8217; AND [Name] = &#8216;My_Table_Name&#8217;) Type = &#8216;V&#8217; for views Type = &#8216;U&#8217; for tables For SQL Server 2008, we can use information_schema.columns for getting column information: SELECT * FROM information_schema.columns WHERE table_name = &#8216;My_Table_Name&#8217; ORDER BY ordinal_position [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[230,1321],"class_list":["post-1805","post","type-post","status-publish","format-standard","hentry","category-sql-server","tag-get-column-names","tag-sql-server"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=1805"}],"version-history":[{"count":5,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1805\/revisions"}],"predecessor-version":[{"id":6426,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/1805\/revisions\/6426"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=1805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=1805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=1805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}