Data Types in SQL

In SQL, data types define the kind of data a column can hold — like numbers, text, or logical values.

Choosing the right data type for each column is important to store and query your data efficiently, accurately.


Commonly Used SQL Data Types

TypeDescriptionExample
INTWhole numbers25, 100, -7
VARCHAR(n)Variable-length text'Alice', 'HR'
BOOLEANLogical true/false valuesTRUE, FALSE
DATECalendar date'2024-01-01'
FLOATApproximate decimal numbers3.14, -0.5

Other SQL Data Types

TypeDescriptionExample
BIGINTVery large integers9223372036854775807
SMALLINTSmaller range integers-32768 to 32767
DECIMAL(p,s)Fixed-point numbers123.45, -99.99
DOUBLEDouble-precision floating point3.14159265359
CHAR(n)Fixed-length text'Y', 'USA'
TEXTLarge blocks of text'This is a long note'
TIMETime of day'14:30:00'
DATETIMEDate and time'2024-01-01 14:30:00'
TIMESTAMPDate and time with timezone awareness'2024-01-01 14:30:00'

Note: Some databases (like SQLite) are more flexible, while others (like PostgreSQL, MySQL, SQL Server) are more strict with data types.

Note: Exact names and available types may vary slightly depending on the database system (e.g., MySQL, PostgreSQL).


Example: Defining a Table with Data Types

CREATE TABLE employees (
  id INT,
  name VARCHAR(50),
  age INT,
  department VARCHAR(50),
  gender VARCHAR(10)
);

We’ll dive deeper into how to create tables in upcoming chapters. For now, this example shows how choosing the right data type helps define what kind of values each column can hold.