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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:27:52+00:00 2026-05-24T00:27:52+00:00

We have a SQL Server 2005 database for which we want to improve performance

  • 0

We have a SQL Server 2005 database for which we want to improve performance of bulk delete/insert/selects and I notice it uses decimal(18,0) for its primary keys. I understand this will give us many more values than bigint but was hoping it might be a quick win and should last us for many million years of growth by my calculations.

I see in the .net docs decimals take 16 bytes instead of the 8 required by longs but in SQL Server it looks like bigint take 8 bytes but the decimal(18,0) takes only 5 bytes – as also seen by select DATALENGTH(max(id)) from table. Is this correct?

Is there any other reason bigint might be slower or should I stick to decimal(18,0)?

  • 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-24T00:27:53+00:00Added an answer on May 24, 2026 at 12:27 am

    DATALENGTH is casting to varchar before counting bytes. So your max value is < 100000.

    The 9 bytes can be proved with this. sys.columns has a max_length column (decimal is fixed length so it is always 9 bytes, before you ask otherwise)

    CREATE TABLE dbo.foo (bar decimal(18,0))
    GO
    SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('foo') 
    GO
    DROP TABLE dbo.foo
    GO
    

    For legacy reasons, decimal(18, 0) was often used as a surrogate for “64 bit integer” before bigint was added with SQL Server 2000.

    decimal(18, 0) and bigint are roughly the same in range: decimal is one byte more at 9 bytes as per the documentation

    On top of that, plain integer will be fractionally (maybe not measurable) faster then decimal. Saying that, if expect to have more then 4 billion rows in the next year or 5, then the performance should matter. If it doesn’t, then just use int

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a database (SQL Server 2005) which we would like to get under
We have a legacy database which is a sql server db (2005, and 2008).
I have a user defined function in a SQL Server 2005 database which returns
I have a sql server 2005 database that I want to setup replication for.
I have a Windows .net application using SQL Server 2005 Express as database, which
I have a SQL Server 2005 database and I have 4 GB of text
I have a SQL Server 2005 database that is suffering from lock starvation because
We have a SQL Server 2005 database, and currently all our users are connecting
I have a SQL Server 2005 database that I'm trying to access as a
I have a SQL Server 2005 database that is linked to an Oracle database.

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.