Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calculating datatype limits i.e. SMALLINT - If SMALLINT is used to defined a user ID, how many users can populate a database before the limit for a table has been reached?

Posted on 2008-06-16
10
Medium Priority
?
730 Views
Last Modified: 2010-04-21
Greetings:

Just as the question states, we have been using SMALLINT to define USER IDs throught our schema.  The concern has been raised that unless the schema is changed so that USER IDs are of type INT, we will exceed capacity.

Two questions:

1)  How does it become obvious that available space will be in danger?  Are we talking about the risk for one particular table (i.e. CompanyUsers) or does this mean there is a risk in every table that contains the USER ID?

2)  How do I go about calculating the amount of space available to show exactly where the database stands?

Thanks
0
Comment
Question by:John500
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
10 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21792852
smallint is around 32,000....Integer data from 32,768 to 32,767. Storage size is 2 bytes.


INT is over 2 billion....Integer (whole number) data from 2^31 (2,147,483,648) through 2^311 (2,147,483,647).
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21792863
Hello John500,

Well smallint has a range of -32768 to 32767 so assuming that you are only using positive numbers for your user id then you have a maximum capacity of 32767 users. Now without knowing how this relates to your circumstances you could consider this to be a reasonable number or not. An int datatype has a capacity of +/- 2147483647 so would give you a much larger potential.

If you determine that 32767 is an insufficient number then you do have the option to double this to 65536 by using negative numbers and not changing the datatypes of your tables or you would have to change the datatype of every column in every table that holds a userID value.

As for calculating where it stands, you need to simply work out how many records there are in your relevant table (allowing of course for the fact that this may be an identity field and that there may be "missing numbers").

Regards,

TimCottee
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21792873
Put negatives on my first numbers...not sure why that didnt' copy over.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

Expert Comment

by:elimesika
ID: 21792894
HI

1) it is no a space that you should concern on , it is the max value your id can handle , after this value is exceeded , you will get negative numbers.

You can do the change easily by using the ALTER TABLE command, since you are only extending it , it's OK.
Do not forget to update any other table in which the user ID is a Foreign Key.

2)
See below , you can support up to 32,767 generated IDs for users in smallint
When using int you got 2,147,483,647

Exact number data types that use integer data.

bigint

Integer (whole number) data from -2^63 (-9,223,372,036,854,775,808) through 2^63-1 (9,223,372,036,854,775,807). Storage size is 8 bytes.

int

Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647). Storage size is 4 bytes. The SQL-92 synonym for int is integer.

smallint

Integer data from -2^15 (-32,768) through 2^15 - 1 (32,767). Storage size is 2 bytes.

tinyint

Integer data from 0 through 255. Storage size is 1 byte.
Remarks
0
 

Author Comment

by:John500
ID: 21793342
When I issue the following statement:

SELECT COUNT(USER_ID) FROM USERS

i get:

-----------
8818

(1 row(s) affected)

Is it correct to say there is no problem because  32,767  -  8818 = 23,949  (available ids)  ??

>>> allowing of course for the fact that this may be an identity field and that there may be "missing numbers"

How could there be any missing numers?  The results of the select statement (8,818) shown above would surely include any identity fields - right ?
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21793368
John500,

Assuming that you haven't deleted any users, or had any inserts fail then your calculation would be accurate, a double check with:

Select Max(User_ID) From Users

Would confirm that of course.

If you have a relatively low growth in user volume over time and you have approx 20000 available user ids then you would be comfortable in keeping the fields with their current datatype. If you expect your user base to increase significantly over time then you should review it.

TimCottee
0
 

Author Comment

by:John500
ID: 21794275
Tim,

The result of Max(User_ID) is :

30,651

>>  If you have a relatively low growth in user volume ...

It's not user volume as much as it is turn-over rate of the IDs.

If I were to delete all unused IDs this would cause an inability to track history on previous users?  Hence, it stands reason the data type needs to change.

Is there any systematic approach that comes to mind where the current ID will not change in spite of the fact that every table using the ID will change from SMALLINT to INT ?

Thanks

0
 
LVL 60

Accepted Solution

by:
chapmandew earned 1000 total points
ID: 21794293
alter table yourtablename
alter column FieldName INT
0
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 1000 total points
ID: 21794377
John500,

chapmandew has the statement you need, you will have to apply this to all tables having the User_ID or equivalent field. So any table which has a column containing this data (whatever the column is actually called) will need to be changed. Because you are simply increasing the storage space for the data, from 2 bytes to 4 bytes and are not actually changing the type (say from Integer data to character data or datetime data) then you will not actually be changing the existing values in any of the tables.

TimCottee
0
 

Author Closing Comment

by:John500
ID: 31467567
Thank you sirs
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question