Over the years I have always used the decimal(18,0) as the datatype for
primary keys. Aside from the number of significant numbers involved,
would BigInt type be better for performance or is decimal(18,0) still okay.
--
Don Vaillancourt
Director of Software Development
WEB IMPACT INC.
phone: 416-815-2000 ext. 245
fax: 416-815-2001
email: do**@web-impact.com <mailto:do**@we bimpact.com>
web: http://www.web-impact.com
Web Impact Inc. <http://www.web-impact.com>
This email message is intended only for the addressee(s) and contains
information that may be confidential and/or copyright.
If you are not the intended recipient please notify the sender by reply
email and immediately delete this email.
Use, disclosure or reproduction of this email by anyone other than the
intended recipient(s) is strictly prohibited. No representation is made
that this email or any attachments are free of viruses. Virus scanning
is recommended and is the responsibility of the recipient. 35 3215
BIGINT is stored one byte smaller than DECIMAL(18,0). 8 bytes vs. 9
bytes.
Not likely to significantly change performance unless you're talking
millions of rows being processed.
I always thought that decimal stored it's values in text format. So for
decimal(18,0) MSSQL would take up 18 bytes. Or am I partially right and
MSSQL uses a nibble to represent a digit.
Gary wrote: BIGINT is stored one byte smaller than DECIMAL(18,0). 8 bytes vs. 9 bytes.
Not likely to significantly change performance unless you're talking millions of rows being processed.
--
Don Vaillancourt
Director of Software Development
WEB IMPACT INC.
phone: 416-815-2000 ext. 245
fax: 416-815-2001
email: do**@web-impact.com <mailto:do**@we bimpact.com>
web: http://www.web-impact.com
Web Impact Inc. <http://www.web-impact.com>
This email message is intended only for the addressee(s) and contains
information that may be confidential and/or copyright.
If you are not the intended recipient please notify the sender by reply
email and immediately delete this email.
Use, disclosure or reproduction of this email by anyone other than the
intended recipient(s) is strictly prohibited. No representation is made
that this email or any attachments are free of viruses. Virus scanning
is recommended and is the responsibility of the recipient.
That is not correct. DECIMAL (18,0) uses 9 bytes stored in hexadecimal
format, not text format. Check BOL.
On Wed, 09 Feb 2005 15:06:33 -0500, Don Vaillancourt wrote: I always thought that decimal stored it's values in text format. So for decimal(18,0 ) MSSQL would take up 18 bytes. Or am I partially right and MSSQL uses a nibble to represent a digit.
Hi Don,
From Books Online:
Precision Storage bytes
1 - 9 5
10-19 9
20-28 13
29-38 17
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Just a thought,
I have found that using unique identifiers for PK columns have benefits
enough to outweigh the size and code differences.
If i use a Unique identifier i do not need to make a return trip to a
client with the id generated by the Database. I can create a Unique
identifier almost anywhere and push the parent pk to the children
without a need for all of the Create a Parent step, now create details,
now create details for the details.
Also, When i use GUID for pk i can mix together values from different
tables and still have a unique column within the view. for example I
can grab address info from both the Customer and the Vendor tables to
create a view that can return all addresses.
anyway, just a thought
Tal
The only caveat to using unique identifier is that it can create
indexes that are up to four times larger than using an int, for
example. That could cause as much as 4X disk I/O to retrieve your disk
pages. Only a concern for large tables, though.
Don Vaillancourt (do**@webimpact .com) writes: I always thought that decimal stored it's values in text format. So for decimal(18,0) MSSQL would take up 18 bytes. Or am I partially right and MSSQL uses a nibble to represent a digit.
The format you get up to a client is a record with precision, scale
and sign, and there are up to 16 bytes for the value.
typedef struct tagDB_NUMERIC {
BYTE precision;
BYTE scale;
BYTE sign;
BYTE val[16];
} DB_NUMERIC;
As for the question whether to use bigint or decimal(18,0), my answer is
neither. The prime option should be to use natural keys, and natural
keys rarely calls for 64-bit numbers. When you need artificial keys,
integer should do in most cases.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
Erland, where did you get that typedef code? Is that from SQL Server
source code?
> When i use GUID for pk i can mix together values from different tables and still have a unique column within the view.
Why is that an advantage? If two rows represent the same physical
entity then you usually want to be able to identify them as being the
same - otherwise you end up with unwanted duplicates. That is why
natural keys are important. Billing the same customer twice isn't
usually good for business!
--
David Portas
SQL Server MVP
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sanjay Minni |
last post by:
What is the datatype to be used
for Primary Key columns for most
optimised access given that
- There will be a single column primary key only
- The values will only be integers (but as
strings) at least 12 digits (characters) long
- all positions will be occupied (no leading 0's)
- Tables may have upto 1m+ rows
|
by: Eternally |
last post by:
Hi folks,
I've got a program which has a function which uses templates to accept
parameters of any type.
Works well, but there's one certain datatype which I want to special case
and do an extra thing to. The datatype is a class I made.
Is there anyway for me to test a parameters datatype in a template using
function?
|
by: SoYouKnowBrig |
last post by:
Hi All,
I am using Microsoft.ApplicationBlocks.Cache.CacheManager to persist a
System.Data.Dataset object. This Dataset object has a DataTable that is
created from an existing DataTable using the Clone() method. Before I
add the new DataTable to the DataSet, I change the DataType of a
DataColumn from System.String to System.Int64. I then add data to the
new table and then add it to the DataSet. Then DataSet is then added to
the Cache....
|
by: Elias Farah |
last post by:
Hi All,
What are people's experience in timing Query Performance? I have
tried in vain, but get many unpredictable results, with execution
proceeding in the background and problems of timing precision.
I am trying to assess my applications performance difference using FK
using BYTE instead of LONG type. and not enforcing integrity at the
database level. (ie, Form level). This only becomes SIGNIFICANT when
the field is used highly in...
|
by: Jim Heavey |
last post by:
I just can not figure out how to provide the information correctly to this
method...
When creating a DataParameter, one of the properties which need to be set
is the datatype. To do this, I would do the following..
dc.DataType = typeof(string)
This of course assumes the datatyp that I an trying to set up is "string".
| |
by: ad |
last post by:
I use ado.net to fill a Excel wroksheet into a DataTable.
The data in the Excel wroksheet is digital.
After the data filled into the DataTable, the DataType of each column is set
to
Double, but I want to treat them as string, I use the code to covert them
DataTable dt = ds.Tables0];
int iColCount = dt.Columns.Count;
for (int j = 0; j < iColCount; j++)
|
by: Johan Delimon |
last post by:
"The active directory datatype cannot be converted to/from a native DS
datatype"
I have an ASP.NET web page that uses queries to AD to identify current users.
Delegation is configured in AD and works as expected.
But sometimes I get an error : "The active directory datatype cannot be
converted to/from a native DS datatype"
And the only way to resolve this error is to kill the aspnet_wp.exe manually.
|
by: Sri |
last post by:
In VB, to know the field type of a column stored in a recordset the command I
use is
If rsQuery.Fields(k).Type = adCurrency Then
How will I achieve the same in ASP.net. I could not find a currency data
type in asp.net and the type is idenfied as decimal.
I have two fields defined in Sql-Server, one is money and other is decimal.
In asp.net both are identified as decimal.
|
by: Prabu Subroto |
last post by:
Dear my friends...
I want to change the datatype of a completed table
(has had already content).
But I don't know how.
Here is my try:
"
kv=# alter table customer alter column address set
type char(150);
ERROR: syntax error at or near "type" at character 47
|
by: Bryan |
last post by:
I have a class called "Prop". I want that class to have a property
called "DataType" where the user can select and store a datatype. How
can I store a DataType value in a class property.
how the code would work in my mind:
dim TempProp as new Prop
TempProp.DataType = String
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |