Numeric Data Types
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
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
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
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
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
CREATE TABLE codes (id INT ZEROFILL);
INSERT INTO codes VALUES (7);
- लगभग 2.1 billion से ज़्यादा हो सकने वाली value के लिए
INTइस्तेमाल करना, जबBIGINTचाहिए। - money के लिए
FLOATइस्तेमाल करना, जो0.1 + 0.2जैसी rounding errors देता है। - एक
UNSIGNEDcolumn में एक negative number store करना, जो strict mode में fail होता है।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: