8.1

Key Categories of Data Types

  • Integer Types

    • Represent positive and negative whole numbers.

  • Decimal Types

    • Represent numbers with fractional values.

  • Character Types

    • Represent textual data (e.g., letters, words).

  • Time Types

    • Represent date and time values or both.

  • Binary Types

    • Store data exactly as it appears in memory or files, bit for bit.

  • Semantic Types

    • Based on other types, with additional special meanings.

  • Simple Data Types

    • Have simple internal structures and are easy to understand.

Complex Data Types

  • Spatial Types

    • Store geometric information such as lines, polygons, and map coordinates.

  • Composite Types

    • Support collections of different values, usually organized in sets or arrays.

  • Document Types

    • Contain textual data in a structured format, for example, XML or JSON.

  • Object Types

    • Enable object-oriented programming capabilities (e.g., methods, subclasses).

User-Defined Types

  • System-Defined Types

    • Built-in types provided by the database systems (e.g., FLOAT, CHAR, ENUM, SET).

  • User-Defined Types

    • Created by database designers to meet specific application needs using the CREATE TYPE statement.

    • Example statements:

      • CREATE TYPE Size AS ENUM ('Small', 'Medium', 'Large', 'XLarge');

      • Used in tables as:

        CREATE TABLE Clothing (
            ItemNumber INTEGER,
            ItemName VARCHAR(20),
            ItemSize Size
        );
        INSERT INTO Clothing VALUES (3281, 'Sahara sun bonnet', 'Small');
        INSERT INTO Clothing VALUES (3400, 'Zephyr shorts', 'XLarge');

Important Points about CREATE TYPE

  • CREATE TYPE allows for defining new types based on existing system-defined types.

  • User-defined types can be used in table definitions.

Quiz Questions Review

  1. Which database does not support the CREATE TYPE statement?

    • Answer: MySQL

  2. User-defined types can be:

    • Answer: Either simple or complex types.

  3. System-defined types can be:

    • Answer: Either simple or complex types.

Examples of System-Defined Types

  • Simple Types: INTEGER, DECIMAL

  • Complex Types: JSON, XML