In MySQL, there are various data types available to store different types of data. Here are some common data types in MySQL along with examples:
1. INTEGER: Signed integer with a maximum range of -2147483648 to 2147483647.
CREATE TABLE example_table (
id INTEGER
);
2. VARCHAR: Variable-length character string with a maximum length specified.
CREATE TABLE example_table (
name VARCHAR(255)
);
3. FLOAT: Floating-point number with single precision.
CREATE TABLE example_table (
price FLOAT
);
4. DOUBLE: Floating-point number with double precision.
CREATE TABLE example_table (
price DOUBLE
);
5. DECIMAL: Fixed-point number with exact precision and scale.
CREATE TABLE example_table (
amount DECIMAL(10, 2)
);
6. DATE: Date value in the format 'YYYY-MM-DD'.
CREATE TABLE example_table (
birth_date DATE
);
7. TIME: Time value in the format 'HH:MM:SS'.
CREATE TABLE example_table (
check_in TIME
);
8. DATETIME: Date and time value in the format 'YYYY-MM-DD HH:MM:SS'.
CREATE TABLE example_table (
created_at DATETIME
);
9. BOOLEAN: Boolean value representing TRUE or FALSE.
CREATE TABLE example_table (
is_active BOOLEAN
);
10. ENUM: Enumeration type with a list of permitted values.
CREATE TABLE example_table (
status ENUM('active', 'inactive', 'pending')
);
These are some commonly used data types in MySQL, and they can be used to define columns in tables. Each data type has specific storage requirements and constraints that should be considered when designing database schemas.
No comments:
Post a Comment