Contents Index Lesson 5: Design column properties Connecting Your Application to its Database

ASA Getting Started
  Designing and Building Your Database
    Tutorial: Design and build a simple database

Lesson 6: Design and create relationships between tables


In this lesson, you learn about designing and creating relationships between tables, using foreign keys.

For more information, see Tables are related by foreign keys.

Concepts 

Although each table contains information about a single subject, two or more tables may contain related information. For example, an employee is a member of a department, or a sales order is for a set of products. Relationships in a database may appear as foreign key relationships between tables, or may appear as separate tables themselves. You will see examples of each in this chapter.

You create relationships in your database to encode rules or practices that govern the data in your tables. Once a relationship is built into the structure of the database, there is no provision for exceptions.

Relationships among tables are classified as follows.

Exercise 

Add foreign keys to relate the tables in your database.

Add the following foreign keys:

The first two foreign keys taken together build the many-to-many relationship between sales orders and products into the database.

To create a foreign key

  1. Select the table for which you wish to create a foreign key.

  2. Click the Foreign Keys tab in the right pane.

  3. From the File menu, choose New > Foreign Key to open the Foreign Key Creation wizard.

  4. Follow the instructions in the wizard.

This completes this introductory section on designing and building relational databases. Remaining chapters in the book describe how to add and retrieve data from databases. These chapters use the Adaptive Server Anywhere sample database, which is a bigger database than the one you have just created.


Contents Index Lesson 5: Design column properties Connecting Your Application to its Database