Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 2: SQL Data Types and Literals

Lesson 14 of 28 in the free Database Management Systems notes on Siksha Sarovar, written by Rohit Jangra.

14.1 Understanding SQL Data Types

Every column in a database table must be assigned a Data Type. This tells the DBMS what kind of data is allowed in that column and how much space to allocate.

Common Data Types Category-wise

CategoryData TypeDescription
NumericINTStandard integer values.
DECIMAL(p,s)Fixed-point numbers (e.g., money). p is precision, s is scale.
FLOATFloating-point (approximate) numbers.
StringCHAR(n)Fixed-length string. Space-padded if shorter.
VARCHAR(n)Variable-length string. Efficient for varying text sizes.
TEXTLarge amounts of character data.
Date/TimeDATEStores YYYY-MM-DD.
TIMESTAMPStores date and time (including timezone in some systems).
TIMEStores HH:MM:SS.
BooleanBOOLEANStores TRUE, FALSE, or UNKNOWN (NULL).

14.2 Literals in SQL

Literals are the actual constant values used in SQL statements.

  1. String Literals: Enclosed in single quotes (e.g., 'Rahul', 'New York').
  2. Numeric Literals: Numbers written without quotes (e.g., 100, 3.14, -45).
  3. Date Literals: Usually strings in a specific format (e.g., '2023-12-31').
  4. NULL Literal: Represents the absence of a value. It is NOT zero or an empty string.

14.3 Choosing the Right Type

  • Use VARCHAR instead of CHAR unless the data is ALWAYS the same length (like a Country Code or Gender).
  • Use DECIMAL for financial calculations to avoid rounding errors common with FLOAT.