PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

Data Types

← All stacks

Theory

4/439

Data Types

A data type is the kind of value a column can hold. INT is a whole number (roll, marks). VARCHAR(50) is short text (name). DATE is a calendar day. DECIMAL(10,2) is money — not FLOAT, because 0.1 + 0.2 in binary floats is messy.

Pick the smallest type that fits. Marks 0–100 → TINYINT or INT, not VARCHAR. Phone as VARCHAR, not INT — leading zero and +91 will break. ENUM is a short fixed list (‘pass’,‘fail’) — don’t use it for a list that grows every week.

NULL means ‘unknown’, not zero and not empty string. A marks column can be NULL if the exam is not written yet. Don’t write WHERE marks = NULL. Write WHERE marks IS NULL.

Board: CREATE TABLE students (roll INT PRIMARY KEY, name VARCHAR(50) NOT NULL, marks INT, dob DATE). That one line teaches types better than a chart of 40 names.

Trap: storing money in FLOAT. Trap: VARCHAR(1) for names. Trap: using TEXT for every column ‘just in case’ — indexes and memory suffer.

On the example next to this theory: Data Types: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Exam tip

INT / VARCHAR / DATE / DECIMAL. Show one CREATE TABLE. NULL ≠ 0.

Data Types — sample query

-- Data Types
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

Data Types: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefColumn type = what value is allowed (INT, VARCHAR, DATE, DECIMAL).
  • RuleMoney → DECIMAL. Names → VARCHAR. Unknown → NULL.
  • RememberWHERE col IS NULL, never = NULL.
  • TrapFLOAT for money; INT for phone numbers.

Questions

1

What is a data type?

2

Which type for money?

3

How do you test NULL?

4 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.