T-SQL 101: #35 What do we mean by data types in SQL Server?

When you store data in a database,  individual values are stored in columns. Now columns have 2 basic characteristics:

  • Data type
  • Nullability

Another common characteristic is:

  • Size (can be maximum length, precision, scale, etc.)

The first of these, the data type of the column, determines what types of value can be stored in the column. For example, I might have an email address and I might decide that that is a string of characters, but I might also have a price and might decide that that needs to be a number of some type.

The second important characteristic (i.e. nullability), decides if in any row, a value is required in that column or not. When a value is missing, we say the column is NULL. (Note: we don't say that the column has a value of NULL).

We use the third characteristic (i.e. size) to further constrain the allowable values in the column. So:

char(10) NULL

means that up to 10 characters can be stored in the column but no more, and the value can also be missing.

Not every data type has a size as a separate characteristic. For example, with tinyint, smallint, int, and bigint, the designers of SQL Server decided to use different data type names for different sizes. They could just as easily have used something like int(1), int(2), int(4), int(8) instead.

Note: tinyint is different to just being a smaller value of int, because it's actually an unsigned whole number (i.e. it cannot have a negative value), where the others are signed whole numbers.

Either way, the data type is really important, as is, determining whether or not a column must have a value.

Learning T-SQL

It's worth your while becoming proficient in SQL. If you'd like to learn a lot about T-SQL in a hurry, our Writing T-SQL Queries for SQL Server course is online, on-demand, and low cost.

Leave a Reply

Your email address will not be published. Required fields are marked *