1. Learn
  2. /
  3. Courses
  4. /
  5. Creating PostgreSQL Databases

Connected

Exercise

Improving object-to-data mapping

The Small Business Development Center client table was previously defined without the inclusion of a point of contact for the client. The initial instinct of the database team was to simply add contact_name and contact_email columns to the client table. However, you object to this plan due to your instincts regarding proper data organization. In the future, a contact might be referenced in multiple tables. In this exercise, you will define table structures for the client and contact information that better separates the client and contact objects.

Recall the previous definition of the client table:

CREATE TABLE client (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50),
    site_url VARCHAR(50),
    num_employees SMALLINT,
    num_customers INTEGER
);

Instructions

100 XP
  • Create a contact table with columns id (a primary key), name (max length of 50), and email (max length of 50).
  • Alter the client table by adding a contact_id column as a foreign key.