Skip to main content

Command Palette

Search for a command to run...

Data type in SQL

Updated
3 min readView as Markdown

🧠 What are Data Types in SQL?

In SQL, data types define what kind of data can be stored in each column of a table—such as numbers, text, dates, or true/false values.

When you create a table, you must choose the correct data type for each column.


🔢 1. Numeric Data Types

Used to store numbers, like marks, price, quantity, etc.

Data TypeDescriptionExample
INTInteger (whole numbers)100, -50
SMALLINTSmaller whole numbers300
BIGINTVery large whole numbers99999999999
DECIMAL(p,s)Exact decimal number, p = total digits, s = after decimalDECIMAL(5,2) → 123.45
NUMERIC(p,s)Same as DECIMALNUMERIC(6,2) → 99.99
FLOATApproximate decimal number3.14
REALLess precision than FLOAT1.23

📝 2. Character/String Data Types

Used to store text like names, addresses, etc.

Data TypeDescriptionExample
CHAR(n)Fixed length string, always uses n spacesCHAR(5) → 'Hi '
VARCHAR(n)Variable length string (up to n characters)VARCHAR(10) → 'Hello'
TEXTLarge amount of text'This is a comment'

📅 3. Date and Time Data Types

Used to store date and/or time.

Data TypeDescriptionExample
DATEOnly date'2025-08-03'
TIMEOnly time'14:30:00'
DATETIMEBoth date and time'2025-08-03 14:30:00'
TIMESTAMPLike DATETIME, used in logs'2025-08-03 14:30:00'

✅ 4. Boolean Data Type

Stores true/false (yes/no) values.

Data TypeDescriptionExample
BOOLEANTRUE (1) or FALSE (0)TRUE

🧪 5. Other Data Types (Special Use)

Data TypeDescriptionExample
BLOBBinary Large Object (files, images)(used to store files)
UUIDUnique identifier'550e8400-e29b...'
JSONJSON formatted data'{"name": "Amit"}'

🧾 Example Table With Data Types

Here’s an example of a table that uses different types of data:

CREATE TABLE Students (
    StudentID INT PRIMARY KEY,         -- number (whole)
    Name VARCHAR(50),                  -- text
    DOB DATE,                          -- date
    Score DECIMAL(5,2),                -- number with decimal
    IsActive BOOLEAN                   -- true/false
);

This table will store:

  • StudentID: Unique number for each student

  • Name: Up to 50 characters

  • DOB: Date of birth

  • Score: Like marks (e.g., 88.75)

  • IsActive: Whether the student is active or not (TRUE/FALSE)


📌 Quick Summary Table

CategoryData Types
NumericINT, DECIMAL, FLOAT, BIGINT, SMALLINT
TextCHAR, VARCHAR, TEXT
Date/TimeDATE, TIME, DATETIME, TIMESTAMP
BooleanBOOLEAN
OthersJSON, UUID, BLOB

✅ INSERT Commands (Add Rows)

Here are a few examples inserting different students:

INSERT INTO Students (StudentID, Name, DOB, Score, IsActive)
VALUES (1, 'Amit Singh', '2002-05-10', 89.75, TRUE);

INSERT INTO Students (StudentID, Name, DOB, Score, IsActive)
VALUES (2, 'Priya Sharma', '2001-11-22', 92.50, TRUE);

INSERT INTO Students (StudentID, Name, DOB, Score, IsActive)
VALUES (3, 'Rahul Mehta', '2003-03-15', 76.00, FALSE);

INSERT INTO Students (StudentID, Name, DOB, Score, IsActive)
VALUES (4, 'Anjali Verma', '2002-08-01', 84.25, TRUE);

More from this blog

Amit singh's blog

235 posts