SQL Data Types: INT & SMALLINT

Instructor: Kaitlin Oglesby

Kaitlin has a BA in political science and experience teaching.

As databases are often used to store numbers and other quantitative data, it is important to recognize differences between data types. This lesson explains a number of different styles.

Different Types of Numbers

As you may have heard by now, Structured Query Language (SQL) allows you to save data into fields using specified types, aptly named 'data types'. However, because SQL can manage truly massive databases, there comes a point where all that data is starting to really be a point of concern. If your database holds numbers and other quantitative data, it's not the size of the number that causes the storage requirements to jump, but instead the size of the blank.

Think about it like this. Imagine two blanks, one for your name, and the other for your address. You'd expect the address blank to be larger than your name blank. As a result, it takes up more space on the page.

To address this issue and limit the size of the blanks, SQL has a number of fields for numbers. Two of them will be discussed here - INT and SMALLINT.

INT

For most database developers, INT is one of the first data fields that they learn to use. After all, it is pretty easy to get that INT means integer, which refers to the fact that there must be a number present. A field that is labeled with INT can hold a range of 4,294,967,296 different numbers. This is because four bytes have been given over to filling the space.

Remember that each byte holds 8 bits of data, and that each bit can only be a one or a zero. To go down to the digital level, four bytes is 32 bits, which has two options, so INT gives you 2^32, or approximately 4.2 billion different values. For many of us, this will be more than enough room to represent the numbers needed.

SMALLINT

However, once you get to the point that you are managing and designing much larger databases, you may want to limit the size of the number that can be placed there. This is especially true if you are managing a database that is made up of a large amount of numbers - by limiting the size of the data, you could reduce your storage usage by almost half!

To do this, you'll need SMALLINT. While INT lets you have up to 4 bytes per entry, SMALLINT limits you to 2. 2 x 8 = 16, so as a result, you only have a range of 65,536 (2^16) different numbers. Needless to say, that is still plenty, but may not suit every use.

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support