If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > general rule for max pk field length?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-15-09, 13:58
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
general rule for max pk field length?

Is there a field length I should not exceed for my primary key field length if I want to be compatible with most DBMS?
Reply With Quote
  #2 (permalink)  
Old 02-15-09, 15:55
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
what is the datatype of this key that you have in mind?

when people speak of "field length" it usually means a VARCHAR column, but i thought i'd ask to make sure
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-15-09, 16:57
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
I'm drawing the ERD in visio, which uses Access perspective. Char. type is TEXT, though VARCHAR would work as well. Does the answer differ between the two?
Reply With Quote
  #4 (permalink)  
Old 02-15-09, 17:52
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
What's the maximum length? And the RDBMS?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #5 (permalink)  
Old 02-15-09, 20:22
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
Since I'm building a generic model (I don't know what RDBMS I'll employ, though I'm using Access for now), I'm looking for a rule-of-thumb figure. I'm trying to avoid having to change field names later, depending upon what RDBMS I settle on.
Reply With Quote
  #6 (permalink)  
Old 02-15-09, 20:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
rule of thumb: maximum 255 bytes

any more than that and i would question the viability of this column as a key

and you would ~never~ need to adjust a column name based on the RDBMS chosen, assuming you do not use special characters in the name


say, i just realized something -- are you talking about the length of the column, or the length of the name of the column???

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Last edited by r937; 02-15-09 at 20:29.
Reply With Quote
  #7 (permalink)  
Old 02-16-09, 23:11
rbfree rbfree is offline
Registered User
 
Join Date: Feb 2009
Posts: 104
both

Originally, I was interested in the column length. I could imagine using a primary key with say 10 ANSI characters, so c. 20 bytes. (2 bytes per char. with ANSI chars, right?).

However, what is the max length of a field/column name?

I see now how I confused things inserting "field names." I did mean field lengths. I was thinking about two things as I was writing. Sorry 'bout that.
Reply With Quote
  #8 (permalink)  
Old 02-17-09, 01:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
2 bytes per character only in some character encodings (unicode?)

maximum length of column for viability as a key is (in my opinion) 255 bytes, preferably substantially less

maximum length of column name varies by database system (access 64, sql server 128, as little as 6 characters for a couple of older ones) but for practical purposes shouldn't be any longer than ~40 characters
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On