SQL Data type

INTEGER:

Integer it represents whole numbers without decimal points.

                                                    
                                                    CREATE TABLE example (
    id INTEGER,
    age INTEGER
);
                                                    
                                                

VARCHAR(size):

Varchar is a kind of data type that Variable-length character strings with a specified maximum size.

                                                    
                                                    CREATE TABLE example (
    name VARCHAR(50),
    address VARCHAR(100)
);
                                                    
                                                

CHAR(size):

Char are fixed-length character strings.

                                                    
                                                    CREATE TABLE example (
    code CHAR(3),
    country CHAR(20)
);
                                                    
                                                

DECIMAL(precision, scale):

  • Represents fixed-point numbers.
                                  
                                    CREATE TABLE example (
    price DECIMAL(8, 2),
    tax_rate DECIMAL(4, 2)
);
                                  
                                

FLOAT:

  • Represents floating-point numbers.
                                  
                                    CREATE TABLE example (
    temperature FLOAT,
    exchange_rate FLOAT
);
                                  
                                

DATE:

  • Represents a date.
                                  
                                    CREATE TABLE example (
    birthdate DATE,
    order_date DATE
);
                                  
                                

TIME:

  • Represents a time.
                                  
                                    CREATE TABLE example (
    login_time TIME,
    event_time TIME
);
                                  
                                

DATETIME:

  • Represents a combination of date and time.
                                  
                                    CREATE TABLE example (
    created_at DATETIME,
    last_modified DATETIME
);
                                  
                                

BOOLEAN:

  • Represents true or false values.
                                  
                                    CREATE TABLE example (
    is_active BOOLEAN,
    has_discount BOOLEAN
);
                                  
                                

BLOB:

  • Binary Large Object, used to store binary data.
                                  
                                    CREATE TABLE example (
    image BLOB,
    document BLOB
);
                                  
                                

ENUM:

  • Represents a set of predefined values.
                                  
                                    CREATE TABLE example (
    gender ENUM('Male', 'Female', 'Other'),
    status ENUM('Active', 'Inactive')
);
                                  
                                

JSON:

  • Stores JSON data.
                                  
                                    CREATE TABLE example (
    user_data JSON,
    preferences JSON
);
                                  
                                

ARRAY:

  • Represents an array of elements.
                                  
                                    CREATE TABLE example (
    tags ARRAY,
    scores ARRAY
);
                                  
                                

UUID:

  • Universally Unique Identifier.
                                  
                                    CREATE TABLE example (
    user_id UUID,
    order_id UUID
);