How to get the no. of columns?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jith87
    New Member
    • Jul 2007
    • 58

    How to get the no. of columns?

    Is there any way to get the number of columns in a MySql table???
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    You have posted this in the Articles section rather than in Forums. I have moved it across for you.
    Please try to post your questions in the forums in the future!

    Moderator

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      You can use the 'INFORMATION_SC HEMA' database to find things like that:
      [code=mysql]
      SELECT COUNT(*) AS 'Count'
      FROM INFORMATION_SCH EMA.COLUMNS
      WHERE TABLE_NAME = 'tblName'
      AND TABLE_SCHEMA = 'dbName'
      [/code]

      Comment

      • jith87
        New Member
        • Jul 2007
        • 58

        #4
        thanx ere............ ..... it worked out for me......

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by jith87
          Is there any way to get the number of columns in a MySql table???
          If you API supports cursors (the way Python does), then this info is contained in the cursor after the query (number of columns actually queried, not necessarily the number in the table):[CODE=python]nCols = len(cursor.desc ription)[/CODE]

          Comment

          Working...