Counting and Listing the Columns in Table


I am going to explain how you can List all the columns and also count the columns from a table .

The following code snippt will list all the columns from the table


SELECT * FROM information_schema.columns
WHERE table_name = '<table_name>' AND table_catalog='<database_name>'



you may ommit the table

SELECT count(1) FROM information_schema.columns
WHERE table_name = '<table_name>'


Note: Please note that the table name should be correct other wise it will return 0


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: