ADD key CONSTRAINTs to the tables
Two of the tables in your database already have well-suited candidate keys consisting of one column each: organizations
and universities
with the organization
and university_shortname
columns, respectively.
In this exercise, you'll rename these columns to id
using the RENAME COLUMN
command and then specify primary key constraints for them. This is as straightforward as adding unique constraints (see the last exercise of Chapter 2):
ALTER TABLE table_name
ADD CONSTRAINT some_name PRIMARY KEY (column_name)
Note that you can also specify more than one column in the brackets.
This exercise is part of the course
Introduction to Relational Databases in SQL
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Rename the organization column to id
___ ___ organizations
___ ___ organization TO ___;
-- Make id a primary key
ALTER TABLE organizations
___ ___ organization_pk ___ KEY (___);