Académique Documents
Professionnel Documents
Culture Documents
Each contact has the following information: first name, last name, email, and phone.
Both email and phone must be unique. In addition, each contact belongs to one or many
groups, and each group has zero or multiple contacts.
Because the primary key consists of one column, you can use column constraint to
make the contact_id column as the primary key.
The first_name and last_name columns have TEXT storage class and those columns
are NOT NULL . It means you must provide values when you insert or update rows in the
contacts table.
The email and phone are unique therefore you use the UNIQUE constraint for each
column.
The following statement creates groups table:
CREATE TABLE groups (
group_id integer PRIM
name text NOT NULL
);
Try It
The contact_groups table has a primary key that consists of two columns: contact_id,
group_id .
To add the primary key constraint you use PRIMARY KEY table constraint.
PRIMARY KEY (contact_id, grou