Advertisement

Responsive Advertisement

SQL Data Types

 


SQL Data Types

Each column in a database table is required to have a name and a data type.

An SQL developer must decide what type of data that will be stored inside each column when creating a table. The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data.

Note: Data types might have different names in different database. And even if the name is the same, the size and other details may be different! Always check the documentation!

The Integer Data Types

Integer data types hold numbers that are whole, or without a decimal point. (In Latin, integer means whole.) ANSI SQL defines SMALLINTINTEGER, and BIGINT as integer data types. The difference between these types is the size of the number that they can store.

Below, we can see Microsoft SQL's definition of various integer data types:

Data typeRangeStorage
bigint-2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)8 Bytes
int-2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647)4 Bytes
smallint-2^15 (-32,768) to 2^15-1 (32,767)2 Bytes
tinyint0 to 2551 Byte

For these types, the default size of the column is important. Defining a smaller column size for smaller integer types (if you know the max size in advance) can help keep your tables as small as possible.

Post a Comment

0 Comments