Data Types
Data Types
Data types
can be categorized broadly into numeric, date and time, and string (or character) types.
These are used for storing numbers, including integers and decimals.
a. INT
b. DECIMAL (M, D)
This will store prices with up to 10 digits, 2 of which are decimal places.
c. FLOAT
Stores TRUE or FALSE. MySQL treats it as an alias for TINYINT(1) where 0 is FALSE and
any non-zero value is TRUE.
Example:
Here, IsActive will store whether a user is active (TRUE) or not (FALSE).
a. DATE
b. DATETIME
c. TIMESTAMP
Similar to DATETIME, but also automatically stores the current timestamp when a record is
inserted or updated.
Example:
CREATE TABLE AuditLog (
LogID INT,
ActionTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
This will automatically store the time when a log entry is created.
d. TIME
a. VARCHAR (M)
b. CHAR (M)
Stores fixed-length strings. If the stored value is shorter than the specified length, it is
padded with spaces.
Example:
Stores large text data. Useful for storing paragraphs or long descriptions.
Example:
This will store binary data, such as an image in the form of a binary stream.
a. ENUM
b. SET