Find the number of columns in a table

前端 未结 19 2185
Happy的楠姐
Happy的楠姐 2020-11-27 11:13

It is possible to find the number of rows in a table:

select count(*) from tablename

Is it possible to find the number of columns in a tabl

相关标签:
19条回答
  • 2020-11-27 12:00

    db2 'describe table "SCHEMA_NAME"."TBL_NAME"'

    0 讨论(0)
  • 2020-11-27 12:01

    Using JDBC in Java:

        String quer="SELECT * FROM sample2 where 1=2";
        
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(quer);
        ResultSetMetaData rsmd = rs.getMetaData();
        int NumOfCol=0;
        NumOfCol=rsmd.getColumnCount();
        System.out.println("Query Executed!! No of Colm="+NumOfCol);
    
    0 讨论(0)
  • 2020-11-27 12:03

    It is possible to find the number of columns in a table just by using 3 simple lines of PHP code.

    $sql="SELECT * FROM table";
    $query=mysqli_query($connect_dude,$sql);    
    $num=mysqli_num_fields($query);
    

    $num would return the number of columns on a given table in this case.

    Hopefully,it would help others.

    0 讨论(0)
  • 2020-11-27 12:04
    SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE 
    TABLE_CATALOG = 'database_name' AND TABLE_SCHEMA = 'dbo'
    AND TABLE_NAME = 'table_name'
    
    0 讨论(0)
  • 2020-11-27 12:06
    SELECT COUNT(*)
      FROM INFORMATION_SCHEMA.COLUMNS
     WHERE table_catalog = 'database_name' -- the database
       AND table_name = 'table_name'
    
    0 讨论(0)
  • 2020-11-27 12:06

    Its been little late but please take it from me...

    In the editor(New Query) by select the database object it can be a table too, if we use the Shortcut Key Alt+F1 we will get all the information of the object and I think will solve your problem as well.

    0 讨论(0)
提交回复
热议问题