SQL Data Types

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

SQL DATA TYPES

CHAR AND VARCHAR


CHAR(X) VARCHAR(X)
Fixed-length character data type. It Variable-length character data type. It
always reserves a specified length (X) only stores the actual characters entered,
for the data, padding with spaces if without padding with spaces.
necessary.
Example: If we have a varchar(20) and
Example: If we have a char(10) and we we want to add “Watermelon” in the
want to add “Water” in the field, it will field, it will appear later as
appear later as: “Water ” leaving 5 “Watermelon”.
spaces that we didn’t use.
KEY DIFERENCIES
Varchar and char stores basic characters while nvarchar and nchar stores Unicode
characters, allowing for a broader range of characters from different languages and in
consequence provides support for those.
CHAT GPT SAYS…
“If you anticipate dealing with data in different languages, especially those with
characters not present in the ASCII character set, it's recommended to use the
Unicode counterparts (NCHAR and NVARCHAR). If your application or data is
primarily in English or another language that doesn't require Unicode, you can use
the non-Unicode counterparts (CHAR and VARCHAR).”
TINY INT, SMALL INT,
MEDIUM INT, INT, BIG INT
TAKE IN ACCOUNT THAT…
it’s not necessary to use a big int to store ages for example. Remember that the
choice depends of what you want to store.
The term "float" comes from

DECIMAL/NUMERIC AND the idea that the decimal (or


binary) point can "float"

FLOAT/REAL
relative to the significant
digits of the number. In
other words, the decimal
point can be moved to
represent values of different
Decimal/Numeric Float/Real magnitudes.

Used for storing fixed-point numbers. It Used for storing floating-point numbers
allows you to specify the precision (total with a decimal precision.
number of digits) and scale (number of
digits after the decimal point). In this case, Float data can have
different quantities of decimals.
Example: A decimal(3,2) stores 3-digits
numbers where 2 of them are decimals. Example: A float can be 125.45689 and
also 1.25.
So I can store 1.23 but not 12.5.
CHAT GPT SAYS…
“DECIMAL is used for exact numeric representation, suitable for financial
calculations. FLOAT is an approximate numeric representation, suitable for scientific
calculations.”
DATE, TIME, DATETIME, AND
TIMESTAMP
BLOB AND CLOB
Stores binary data that comes from Stores a large amount of characters data,
images or multimedia files. It’s called such as text documents (tales, news,
BLOB because of “Binary Large articles, etc.). It’s called CLOB because
Object”. of “Character large object”.

You might also like