get number of columns sql

Solutions on MaxInterview for get number of columns sql by the best coders in the world

showing results for - "get number of columns sql"
Paolo
10 Jun 2017
1#With SQL
2
3SELECT count(*)
4FROM information_schema.columns
5WHERE table_name = 'Your_table_name';
6
Lucia
15 Aug 2017
1//With JAVA
2
3String quer="SELECT * FROM sample2 where 1=2";
4
5Statement st=con.createStatement();
6ResultSet rs=st.executeQuery(quer);
7ResultSetMetaData rsmd = rs.getMetaData();
8int NumOfCol=0;
9NumOfCol=rsmd.getColumnCount();
10System.out.println("Query Executed!! No of Colm="+NumOfCol);
Arianna
10 Jan 2018
1SELECT TABLE_NAME , count(COLUMN_NAME)
2FROM information_schema.columns
3GROUP BY TABLE_NAME;
4
5-- Oracle (depending on schema grants):
6SELECT count(*) FROM USER_TAB_COLS WHERE TABLE_NAME = 'my_table';
7SELECT count(*) FROM ALL_TAB_COLS WHERE TABLE_NAME = 'my_table';
8SELECT count(*) FROM DBA_TAB_COLS WHERE TABLE_NAME = 'my_table';