Skip to main content

Relationship cardinality

Can be of three types: one-to-many, one- to-one, or many-to-many.

One-to-many (1:M). The most common type of relationship cardinality is a 1:M relationship. Consider the relationship between the EMPLOYEE and DEPARTMENT tables shown in Figure 1. The common column is DEPARTMENT_ID (which is the primary key in the DEPARTMENT table and the foreign key in the EMPLOYEE table). One individual DEPARTMENT_ID can relate to many rows in the EMPLOYEE table. This represents the business rule that one department can relate to one or many employees (or even no employees) and that an employee is associated with only one department (or, in some cases, no department). This business rule can be restated as follows: Each employee in a department may be in one and only one department, and that department must exist in the department table.



One-to-one (1:1). A 1:1 relationship between the DEPARTMENT table and the MANAGER table is depicted in Figure 2. For every row in the DEPARTMENT table, only one matching row exists in the MANAGER table. Expressing this as a business rule: Every department has at least one and at most one manager, and, conversely, each manager is assigned to at least one and at most one department.



One-to-one data relationships can exist, but they are not typically implemented as two tables (though they may be modeled that way). Instead, the data is combined into one table for the sake of simplicity.

Many-to-many (M:M). Consider the EMPLOYEE and PROJECT tables in Figure 3. The business rule is as follows: One employee can be assigned to multiple projects, and one project can be supported by multiple employees. Therefore, it is necessary to create an M:M relationship to link these two tables.



To support the relational database model, an M:M relationship must be resolved into 1:M relationships. Figure 4 illustrates this resolution with the creation of an associative table (also sometimes called an intermediate or intersection table) named EMPLOYEE_PROJECT.



In this example, the associative table’s primary key—a composite of its Employee_ID and Project_ID columns—is foreign-key-linked to the tables for which it is resolving an M:M relationship. It reflects that one employee can be assigned to multiple projects—and, in this example, that one employee can be assigned multiple and different responsibilities for each project to which that person is assigned. Note that the employee with an EMPLOYEE_ID value of 1234 is assigned to two projects but that his responsibilities are different for each project.

Comments

Popular posts from this blog

Oracle Developer Technical Interview Questions

Here i am putting all the questions i had faced during my interviews ... Interview at “3i InfoTech”, Chennai:  1) What is flow of execution of WHEN-NEW-FORM-INSTANCE, WHEN-NEW-BLOCK-INSTANCE, and WHEN-NEW-ITEM-INSTANCE? 2) What is PRE-QUERY and POST-QUERY? When these triggers will fire? 3) If the object library with some blocks and triggers if a form inherited that object library if u doesn’t need some trigger to be inherited the can u delete that trigger from that form? 4) How u can call a report from a form? Which property u has set in runtime? 5) If u create a relation between two blocks in the form what are all triggers it will create? 6) What is a ref cursor? 7) To call a form which type of built-ins u has to use? 8) What is the main difference between expand and variable property for a text item in reports. 9) In a report layout there is accepted and rejected fields and it has a parameter when u run the report based on the parameter the output should sh...

Difference Between CASE and DECODE?

– CASE is a expression – DECODE is a function - CASE expression is ANSI SQL Statement - DECODE is specific to Oracle Syntax - CASE syntax contains WHEN and THEN  - DECODE will not have this - CASE allow expressions or Scalar Sub query Expressions inside the CASE statement - DECODE won't allow expressions inside the DECODE function

Selecting from the DUAL Table

DUAL is a table automatically created by Oracle along with the data dictionary. DUAL is in the schema of the user SYS, but is accessible by the name DUAL to all users. It has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value ’X’. Selecting from the DUAL table is useful for computing a constant expression with the SELECT statement. Because DUAL has only one row, the constant is returned only once. Alternatively, you can select a constant, pseudocolumn, or expression from any table, but the value will be returned as many times as there are rows in the table