Q

Number of rows and columns

How can I get the number of rows and columns in a SQL table?

How can I get the number of rows and columns that are in an SQL table?

Thank you for such a lovely short question. The number of rows is easy:

select count(*) as rows  
  from daTable

As for the number of columns, that's a bit trickier:

select count(*) as columns
  from information_schema.columns
 where table_name = 'daTable'

The INFORMATION_SCHEMA tables (actually, they're views) are the standard SQL way of storing information about your database, and you are allowed to query them too.

This was first published in January 2007

Dig deeper on Oracle and SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close