Day 2 Notes
Day 2 Notes
SQL is the standard language for database management. All the RDBMS
systems like MySQL, MS Access, Oracle, Sybase, Postgres, and SQL Server
use SQL as their standard database language. SQL programming language
uses various commands for different operations.
DATA TYPES:
In SQL, data types define the type of data that a column or variable can
hold. Each database system has its own set of data types, some common
ones used across different databases:
String Data Types:
CHAR(size): A fixed-length string (can contain letters, numbers, and
special characters). The size parameter specifies the column length in
characters (0 to 255).
VARCHAR(size): A variable-length string (maximum string length from 0
to 65535 characters).
TEXT(size): Holds a string with a maximum length of 65,535 bytes.
ENUM(val1, val2, val3, …): A string object with a single value chosen
from a list of possible values.
SET(val1, val2, val3, …): A string object that can have zero or more
values from a list of possible values.
Numeric Data Types:
BIT(size): A bit-value type (1 to 64 bits per value).
TINYINT(size): A very small integer (signed range: -128 to 127, unsigned
range: 0 to 255).
INT(size): Integer data type (various sizes).
FLOAT(size, d): Floating-point number (single-precision).
DECIMAL(size, d): Exact numeric data type (fixed-point).
Date and Time Data Types:
DATE: Stores date values (YYYY-MM-DD).
TIME: Stores time values (HH:MM:SS).
DATETIME: Stores both date and time values.
TIMESTAMP: Stores date and time, including fractional seconds.
Binary Data Types:
BINARY(size): Stores binary byte strings (size in bytes).
VARBINARY(size): Stores variable-length binary byte strings.
BLOB(size): For binary large objects (up to 65,535 bytes).
Other Data Types:
BOOLEAN: Represents true or false values.
JSON: Stores JSON data.
GEOMETRY: Stores spatial data (used in GIS applications).
Remember that data types ensure data integrity and efficient storage.
Always check the documentation for specific details and variations in
different databases!