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 7818911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:44:08+00:00 2026-06-02T06:44:08+00:00

DBAs have told me that when using T-SQL: select count(id) from tableName is faster

  • 0

DBAs have told me that when using T-SQL:

select count(id) from tableName

is faster than

select count(*) from tablenName

if id is the primary key.

Extrapolating that to LINQ-TO-SQL is the following accurate?

This LINQ-to-SQL statement:

int count = dataContext.TableName.Select(primaryKeyId => primaryKeyId).Count();

is more performant than this one:

int count = dataContext.TableName.Count();
  • 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-02T06:44:10+00:00Added an answer on June 2, 2026 at 6:44 am

    As I understand it there’s no difference between your two select count statements.

    Using LINQPad we can examine the T-SQL generated by different LINQ statements.

    For Linq to SQL both

    TableName.Select(primaryKeyId => primaryKeyId).Count();
    

    and

    TableName.Count();
    

    generate the same SQL

    SELECT COUNT(*) AS [value] FROM [dbo].[TableName] AS [t0]
    

    For Linq to Entites, again they both generate the same SQL, but now it’s

    SELECT 
    [GroupBy1].[A1] AS [C1]
    FROM ( SELECT 
        COUNT(1) AS [A1]
        FROM [dbo].[TableName] AS [Extent1]
    )  AS [GroupBy1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of stored procedures that select data from a db. I
I encountered SQL queries that looked like select hello from foo.bar I found that
I have talked with some Oracle DBAs, and they told that there is a
i have a query to read magazine from db as $select = $db->select() ->from('tbl_magazine',array('magazine_id','magazine_name'))
I have a SQL 2008 DB. I am running a form that backs that
My DBAs have informed me that one of my applications is really bogging down
I have a table in MYSQL in with a primary key id int(11) (auto-incremented).
I am using Microsoft SQL 2005 server. I have created several SP and Functions
I've been migrating a system from MS SQL to Oracle and have been more
I have a db, that stores dates in OleDateTime format, in GMT timezone. I've

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.