get number of columns sql

#With SQL

SELECT count(*)
FROM information_schema.columns
WHERE table_name = 'Your_table_name';

4.5
10
Wren 115 points

                                    //With 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);

4.5 (10 Votes)
0
4.33
6
GreyShift 85 points

                                    SELECT TABLE_NAME , count(COLUMN_NAME)
FROM information_schema.columns
GROUP BY TABLE_NAME;

-- Oracle (depending on schema grants):
SELECT count(*) FROM USER_TAB_COLS WHERE TABLE_NAME = 'my_table';
SELECT count(*) FROM ALL_TAB_COLS WHERE TABLE_NAME = 'my_table';
SELECT count(*) FROM DBA_TAB_COLS WHERE TABLE_NAME = 'my_table';

4.33 (6 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source