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

  • Home
  • SEARCH
  • 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 7802341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:14:05+00:00 2026-06-02T01:14:05+00:00

How does SQL Server determine the order of the columns when you do a

  • 0

How does SQL Server determine the order of the columns when you do a SELECT *?

I know “Order By” is essential for ordering the data, but I expected the column names to be consistent.

Note: My code is not dependent on the actual order the columns are returned. I just want to know how SQL Server decides to order the column names.

Of about 20 computers my team is using, one of them behaves differently. Any difference deserves to be investigated. The column name ordering appears to be the same for all computers when we open SQL Server Management Studio. When our application makes a query is when I see the difference.

I am using SQL Server 2008, and SQL Server 2008 R2. My application uses C# System.Data.SqlClient to access the database.

EDIT:
My problem turned out to be that one of the computers was configured to log in as ‘sa’, instead of the intended user. The query was hitting the table directly when we intended it to hit a view. Thanks for the help learning about sys.columns

  • 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-06-02T01:14:06+00:00Added an answer on June 2, 2026 at 1:14 am

    They are in the order of column_id from the system view sys.columns.

    You can check it by:

    SELECT column_id, name
    FROM sys.columns
    WHERE object_id = Object_id('MyTableName')
    ORDER BY column_id
    

    EDIT

    This is for Dems. You should test on a larger table, but it looks like it uses the order defined in the table, not the index:

    CREATE TABLE #T (cola int, colb int, colc int)
    
    INSERT INTO #T
    VALUES
    (1,2,3),
    (2,3,4),
    (4,5,6)
    
    SELECT * FROM #T
    
    CREATE INDEX ix_test ON #T (colb, colc, cola)
    
    SELECT * FROM #t
    WHERE colb > 0
    
    DROP TABLE #T
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does SQL Server determine whether a table column has low cardinality? The reason
Does anyone know if Data Quality Services in Sql Server 2012 can be used
Does SQL Server 2008 have a a data-type like MySQL's enum ?
Does SQL Server maintains any history to track table alterations like column add, delete,
Why does Sql server doesn't allow more than one IDENTITY column in a table??
When I perform a select/Insert query, does SQL Server automatically create an implicit transaction
This is probably an oldie-but-goodie. I am using System.Data.Common for an interchangeable Oracle/SQL Server/SQLite
I know this is similar to this question , but I'm using SQL Server
Does SQL server expect numbers to be specified with digits from the latin alphabet,
Does SQL Server 2005 maintain built-in, queryable, row-level last-modified timestamp metadata? I'm doing some

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.