sqldatabaserelational-databaseinner-joinself-join

Data model line pointing to itself


I am learning SQl on microsoft learn. During an exercise Microsoft provided a datamodel. On the bottom Right there is a line with a key pointing to itself. What does that mean?

example


Solution

  • That image is too tiny to see anything, but I presume that it represents a foreign key which references a column that belongs to the same table.

    For example, mgr_id is a manager of an employee identified by emp_id. There's also a foreign key from mgr_id to emp_id which means that database will take care about valid values in mgr_id column, i.e. you won't be able to insert ID that doesn't exist in employees.emp_id column.

    CREATE TABLE employees
    (
       emp_id   NUMBER PRIMARY KEY,
       name     VARCHAR2 (20) NOT NULL,
       salary   NUMBER,
       mgr_id   NUMBER REFERENCES employees (emp_id)
    );
    

    ER model (generated by TOAD GUI tool):

    enter image description here


    [EDIT]

    Now that image is enlarged, yes - it seems that ParentProductCategoryID references ProductCategoryID (explanation remains the same).