Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 481677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:01:07+00:00 2026-05-13T01:01:07+00:00

If I know the database-name and table-name, how can I find columns-count of the

  • 0

If I know the database-name and table-name, how can I find columns-count of the table from sql server master database?

What is the fastest way to find the columns count of any database-table?

What do you think about the performance of this query?

select count(*) from SYSCOLUMNS where id=(select id from SYSOBJECTS where name='Categories')

I need to support sql server 2000 and onwards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:01:08+00:00Added an answer on May 13, 2026 at 1:01 am

    It may vary slightly depending on the version of SQL Server, but this will work for 2005:

    SELECT
         COUNT(*)
    FROM
         <database name>.sys.columns
    WHERE
         object_id = OBJECT_ID('<database name>.<owner>.<table name>')
    

    In 2000:

    SELECT
         COUNT(*)
    FROM
         <database name>.sysobjects o
    INNER JOIN <database name>.syscolumns c ON
         c.id = o.id
    WHERE
         o.name = '<table name>'
    

    If you might have multiple tables with the same exact table name under different owners then you’ll need to account for that. I forget the column name in sysobjects to look at off the top of my head.

    UPDATE FOR NEWER VERSIONS OF SQL Server and ANSI compliance:

    SELECT COUNT(*)
    FROM
        <database name>.INFORMATION_SCHEMA.COLUMNS
    WHERE
        TABLE_SCHEMA = '<table schema>' AND
        TABLE_NAME = '<table name>'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I search my sql database for a table that contains a field
I can find tons of examples where you can query a MySQL database from
I've got a database from SQL Server 2005 that I am programmatically attaching to
Does anyone know how to create an entire database from a visual studio database
I have used this statements to populate jcombobox from MySql database table using Hibernate
On the language that I know, RPG... You can use multiple keys and find
I'm trying to get a single value from my table in a database. They
I've looked everywhere, and I can't seem to find an answer one way or
I am working in Sql Server 2008 and there is a change of table
in my database one table is there with say name as tableA.the structure of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.