In this lesson, you will define primary and foreign keys on target tables to use later in a join. To do this lesson, you must have defined the dimension tables and fact table in Defining the rest of the star schema (optional).
In each target table, you will select a column that can be used to uniquely identify rows in that table. This will be the table's primary key. The column that you select as a primary key must have the following qualities:
For example, the CITY_ID column in the LOOKUP_MARKET table (created in Lesson 8, Defining data transformation and movement) is a good candidate for designation as a primary key. Because each city needs an identifier, no two cities can have the same identifier, and identifiers are unlikely to change.
Defining a primary key for a table is highly recommended because uniquely identifying each row speeds up row access.
You use foreign keys to define relationships between tables. In a star schema, a foreign key defines the relationship between the fact table and its associated dimension tables. The primary key of the dimension table has a corresponding foreign key in the fact table. The foreign key requires that all the values of a given column in the fact table also exist in the dimension table. For example, the CITY_ID column of the FACT_TABLE might have a foreign key defined on the CITY_ID column of the LOOKUP_MARKET dimension table. This means that a row cannot exist in the FACT_TABLE unless the CITY_ID exists in the LOOKUP_MARKET table.
In this lesson, you will define primary keys on the four target tables that you created in Lesson 8, Defining data transformation and movement: LOOKUP_MARKET, LOOKUP_TIME, LOOKUP_PRODUCT, and LOOKUP_SCENARIO. You will define corresponding foreign keys in the FACT_TABLE target table.
In this exercise, you will define a primary key for the LOOKUP_MARKET, LOOKUP_TIME, LOOKUP_PRODUCT, and LOOKUP_SCENARIO target tables.
To define the primary keys:
The Alter Table notebook opens.
Follow the same steps to define primary keys for the other target tables. Define:
You need to define foreign keys for the relationships between the FACT_TABLE and the other target tables.
In this exercise, you will define a foreign key in the FACT_TABLE (dependent table) based on the primary key of the LOOKUP_MARKET table (parent table).
To define the foreign keys:
The Alter Table notebook opens.
Accept the defaults for the On delete and On update fields. For more information about these fields, see the online help.
Follow the same steps to define foreign keys for FACT_TABLE to the other target tables. Define:
In this lesson, you defined primary keys for the LOOKUP_MARKET, LOOKUP_TIME, LOOKUP_PRODUCT, and LOOKUP_SCENARIO target tables. You defined foreign keys for the FACT_TABLE that correspond to the primary keys. In Lesson 16, Creating a star schema from within the Data Warehouse Center, you will use these keys to join the tables in the star schema.