How to get number of fields in SQL Server database

1083690 pts.
Tags:
Database
SQL Server
SQL statements
Would I be able to get the number of fields in my SQL Server database with some sort of SQL statement? I'm talking about all the entries in my database. Thank you.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Got his from another site

For all the fields in all the tables? assuming standards (mssql, mysql,
postgres) you can issue a query over information_schema.columns

  SELECT COUNT(*) 
  FROM INFORMATION_SCHEMA.COLUMNS 

Or grouped by table:

  SELECT TABLE_NAME, COUNT(*) 
  FROM INFORMATION_SCHEMA.COLUMNS 
  GROUP BY TABLE_NAME

If multiple schemas has the same table name in the same DB, you MUST
include schema name as well (i.e: dbo.Books, user.Books, company.Books
etc.) Otherwise you’ll get the wrong results. So the best practice is:

SELECT TABLE_SCHEMA, TABLE_NAME, COUNT(*) 
FROM INFORMATION_SCHEMA.COLUMNS 
GROUP BY TABLE_SCHEMA, TABLE_NAME

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • ToddN2000
    Are you referring to the total number of columns in every table in the data base? What is the reason for the strange request?
    108,015 pointsBadges:
    report

Forgot Password

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

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: