There are only a few primitive data types used in most computers. These data types have a specific size and encoding scheme. Below is a table which shows all of the available data types

Type

Size (in bytes)

Description

Examples

Integer

4

Stores normal numbers (not decimals)

10,999,23

Real/Float

4-8

Stores decimal numbers

8.4, 2.112, 3.14

Boolean

1

Stores true/false values

TRUE, FALSE

Characters

1

Stores a single letter

A,Z,B

String

Variable

Collection of characters

“HELLO”, “mOo!”

Date

6

Stores a date

12/01/07

Classes in most languages are considered a data type. These will be made up of one or more primitive data types as shown above. When defining a variable you must specify its data type. Due to the encoding schemes used you can not directly compare different types together. For example it is not possible to compare a real number to a integer. Programming languages get around this by converting them both to a common data type. This process is known as casting. Sometimes you need to directly cast yourself. Consider the code below.

 


A = 10 
B = "My age is"
print A + B
					
					

This code will not compile. This is because we are trying to add a number to a string. Due to the encoding scheme used for both integers and text (ASCii) the programming language needs further instructions on how to handle this. We can use a explicit cast to perform what we want.


print (B + str(A)) 
					
					

Databases use primitive data types for its fields. A single record, therefore, is a collection of primitive data types.