473,794 Members | 3,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What datatype to use for PK?

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.
Jul 23 '05
35 3217

"Don Vaillancourt" <do**@webimpact .com> wrote in message
news:Ci******** ************@nn rp1.uunet.ca...
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.

I think it depends on what your primary key is. If it's an ISBN for
example, I don't think either of these would work.

Jul 23 '05 #11
David Portas (RE************ *************** *@acm.org) writes:
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!


As long as the customer pays both bills it is!

As for the use of artificial keys - if the thing inserted into the database
is an order by a web customer, there is no natural key until it has been
inserted. The order-entry system must generate the key itself.

--
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
Jul 23 '05 #12
Gary (ga**********@w cc.ml.com) writes:
Erland, where did you get that typedef code? Is that from SQL Server
source code?


The OLE DB Refeference Manual in the MDAC Books Online. It's also in MSDN
Library.

Of course, that's a general interface which is independent of the data
source, but I would not be surprised if the format is taken from SQL
server.
--
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
Jul 23 '05 #13
A natural key is simply a product of the way some data is represented
in a table - a subset of the attributes that you need to record. In the
case of an online order that might be (user,order_dat etime) for
example. A natural key is never "generated" internally because it
always represents something that is "outside the system" - that is the
critical distinction between a natural and artificial key.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #14
On 9 Feb 2005 14:00:03 -0800, "ta*********@ho tmail.com"
<ta*********@ho tmail.com> wrote:

[snip]
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.


I'd like to see the conceptual model behind that.

--
Mike Sherrill
Information Management Systems
Jul 23 '05 #15
Conceptually the model is a "bag" rather than a "set" i.e. duplicates
are allowed (the GUID isn't part of the logical model so it doesn't
count). A bag may be useful for a table in a "staging" database as part
of a data transformation process. The transformation then reconciles
and eliminates duplicates so that integrity is maintained.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #16
David Portas (RE************ *************** *@acm.org) writes:
A natural key is simply a product of the way some data is represented
in a table - a subset of the attributes that you need to record. In the
case of an online order that might be (user,order_dat etime) for
example. A natural key is never "generated" internally because it
always represents something that is "outside the system" - that is the
critical distinction between a natural and artificial key.


The natural key for an order - the way users would refer to it - is
the order id. In a paper-based computer-less system, it would be a
pre-printed number on an order book. In a computer-based system, the
order id is generated by the system at the time for the order.

Involving userid is likely to be out of the question in many middle-
tier apps - all orders from the same user. Customer may do better, but
it may be perfectly legal for the same customer to place two orders at
the same time. For instance, the customer may be a company, and two
different departments are making different orders.

And if even if you could construct this natural key, I can tell you that the
users blissfully will ignore it. What they need is an order id, and you
must somehow report that back. In a web app, you sometimes want to avoid
an extra rountrip to get that number. Sending down a GUID from the client
is one way to handle it. A GUID is a poor key for usability, but if it's
reported back to another app in a business-to-business solution, this is
less of an issue.

The idea with a "natural key" as being something "outside the system" may
sound nice, but it does not model the reality for real-life system.

--
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
Jul 23 '05 #17
> Involving userid is likely to be out of the question in many middle-
tier apps - all orders from the same user
True. There may be a difference between "user" and "customer". Customer
is what I meant. Customers do indeed require an order number generated
by the system - no problem there.
it may be perfectly legal for the same customer to place two orders at the same time. For instance, the customer may be a company, and two
different departments are making different orders.
Say, two orders are placed simultaneously by different entities
(departments or whatever) and you don't record the information that
distinguishes them then how will you know which is which? The
artificial order number doesn't tell you that. In your hypothetical
scenario wouldn't the order confirmation emails go to the same address?
So even the customer's Accounts Payable department wouldn't know which
items on the order belonged to which department unless the end-user
recorded that information separately. Is there a benefit in issuing
multiple order numbers in this scenario? I'm not sure, but if there
were and you wanted to persist information about different, arbitrary
"sub-groups" of order items with all other attributes of the order
identical then in 3NF that information belongs as an attribute in the
Order Details table, not as a duplicate in the Order table. That's
unless the "department " attribute was recorded as well, in which case
Department would obviously become part of the Order table's key.
The idea with a "natural key" as being something "outside the system" may sound nice, but it does not model the reality for real-life system.


I thought "real-life" was "outside the system" but maybe your
definition of reality differs from mine. :-)

--
David Portas
SQL Server MVP
--

Jul 23 '05 #18
On 10 Feb 2005 03:28:00 -0800, "David Portas"
<RE************ *************** *@acm.org> wrote:
Conceptually the model is a "bag" rather than a "set" i.e. duplicates
are allowed (the GUID isn't part of the logical model so it doesn't
count).


Not exactly where I was going, but it's in the same direction. I was
using "conceptual model" in the sense Halpin uses it in ORM. And I'd
still like Tal to post it.

--
Mike Sherrill
Information Management Systems
Jul 23 '05 #19
Well no, the PK would be an integer.

Greg D. Moore (Strider) wrote:
"Don Vaillancourt" <do**@webimpact .com> wrote in message
news:Ci******** ************@nn rp1.uunet.ca...
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.

I think it depends on what your primary key is. If it's an ISBN for
example, I don't think either of these would work.

--
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.
Jul 23 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
13454
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
8
1952
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?
0
1688
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....
14
3017
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...
0
929
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".
2
45904
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++)
2
3840
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.
3
3345
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.
1
1480
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
1
1182
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
0
10435
Oralloy
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...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
agi2029
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...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
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();...
0
5436
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...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.