SunQuest
           Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old March 11th, 2008, 07:35 PM
xenoterracide xenoterracide is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: MI, USA
Posts: 64 xenoterracide User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 22 m 5 sec
Reputation Power: 2
Send a message via AIM to xenoterracide Send a message via MSN to xenoterracide Send a message via Yahoo to xenoterracide Send a message via Google Talk to xenoterracide
Int(1) or int(2) design

n00b question. First what I'm asking might not even matter.

I have a int field with real world possible values of 1-10.

I'm wondering if I should use an int(1) or int(2). does it matter? do they use the same amount of space? if they don't I could do some hack that says 0=1 1=2 etc in sql or something and do int(1) or I could do int(2) and just use real values.

another note: actually having the value 10 although technically possible will be very rare if, I would doubt 1 in 1 billion records would have it.

Reply With Quote
  #2  
Old March 11th, 2008, 10:25 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,130 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 4 Days 13 h 13 m 52 sec
Reputation Power: 883
Quote:
Originally Posted by xenoterracide
n00b question.
no prob

first, i would like to draw your attention to the fact that we have several forums for databases -- forums for db2, mysql, postgresql, firebird, ms sql, oracle, and finally the one you posted into, a generic one for databases not covered by the other forums, or for general topics where the database system doesn't matter

judging by your question, i'd say you were using mysql, because mysql is the only one that i know of where people routinely get misled by that silly number in parentheses

no, the number in parentheses doesn't matter

INT(1) is the same as INT(2) is the same as INT(937)

they all take 4 bytes and can hold the same range of numbers

so for what you've described, you should be using TINYINT, not INTEGER

__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old March 12th, 2008, 06:34 PM
xenoterracide xenoterracide is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: MI, USA
Posts: 64 xenoterracide User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 22 m 5 sec
Reputation Power: 2
Send a message via AIM to xenoterracide Send a message via MSN to xenoterracide Send a message via Yahoo to xenoterracide Send a message via Google Talk to xenoterracide
ah... my apologies I didn't realize it was a mysql specific feature (I believe tinyint is as well). I assume it works as a sort of constraint then. thanks for the answer.

Reply With Quote
  #4  
Old March 12th, 2008, 09:28 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,130 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 4 Days 13 h 13 m 52 sec
Reputation Power: 883
not a constraint, no

the number in parentheses specifies how many total digits including leading zeroes you want to display if you are using the ZEROFILL option


Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Int(1) or int(2) design


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway