← Back to MySQL Course | Chapter 3: Data Types | Lesson 1 of 8

Numeric Data Types

Numeric types numbers के लिए अलग-अलग sizes के boxes जैसे हैं: छोटे numbers के लिए एक tiny box और enormous numbers के लिए एक giant वाला। सबसे छोटा वाला चुनें जो fit हो।
Syntax
sql
column_name INT | TINYINT | BIGINT | DECIMAL(precision, scale) | FLOAT | DOUBLE

Integer Types

Integer types TINYINT (1 byte, unsigned तक 255) से लेकर BIGINT (8 bytes, enormous range) तक range करते हैं — आपके data में comfortably fit होने वाला सबसे छोटा type चुनना storage बचाता है और बड़ी tables पर indexes तेज़ करता है।

उदाहरण: Integer Types

sql
CREATE TABLE items (
  small_count TINYINT,
  big_count BIGINT
);

Decimal Types

DECIMAL numbers को approximations के बजाय exact fixed-point values की तरह store करता है, इसे currency और दूसरे figures के लिए सही choice बनाते हुए जहाँ कई calculations में छोटा भी rounding drift unacceptable है।

उदाहरण: Decimal Types

sql
CREATE TABLE invoices (amount DECIMAL(10,2));
INSERT INTO invoices VALUES (19.99);

Float और Double

FLOAT और DOUBLE speed और compactness के लिए थोड़ी precision trade करते हैं, जो scientific measurements या graphing data के लिए ठीक है लेकिन invoices जैसी किसी exact totals चाहिए होने वाली चीज़ के लिए risky है।

उदाहरण: Float and Double

sql
CREATE TABLE measurements (temperature FLOAT, distance DOUBLE);

Unsigned Numbers

किसी numeric column को UNSIGNED mark करना negative values store करने की ability हटा देता है लेकिन available positive range double कर देता है — age या quantity जैसे columns के लिए एक अच्छा fit जो वैसे भी कभी negative नहीं होते।

उदाहरण: Unsigned Numbers

sql
CREATE TABLE people (age INT UNSIGNED);

Zerofill Attribute

ZEROFILL किसी numeric column की displayed value को उसकी defined width तक leading zeros से pad करता है (जैसे 7 के बजाय 007), और एक side effect की तरह यह column को implicitly UNSIGNED भी बना देता है।

उदाहरण: Zerofill Attribute

sql
CREATE TABLE codes (id INT ZEROFILL);
INSERT INTO codes VALUES (7);

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. लगभग 2.1 billion से ज़्यादा हो सकने वाली value के लिए INT इस्तेमाल करना, जब BIGINT चाहिए।
  2. money के लिए FLOAT इस्तेमाल करना, जो 0.1 + 0.2 जैसी rounding errors देता है।
  3. एक UNSIGNED column में एक negative number store करना, जो strict mode में fail होता है।
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.