Get startedGet started for free

Test your knowledge before advancing

Before you move on to the next chapter, let's quickly review what you've learned so far about attributes and key constraints. If you're unsure about the answer, please quickly review chapters 2 and 3, respectively.

Let's think of an entity type "student". A student has:

  • a last name consisting of up to 128 characters (required),
  • a unique social security number, consisting only of integers, that should serve as a key,
  • a phone number of fixed length 12, consisting of numbers and characters (but some students don't have one).

This exercise is part of the course

Introduction to Relational Databases in SQL

View Course

Exercise instructions

  • Given the above description of a student entity, create a table students with the correct column types.
  • Add a PRIMARY KEY for the social security number ssn.

Note that there is no formal length requirement for the integer column. The application would have to make sure it's a correct SSN!

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Create the table
___ ___ students (
  last_name ___(___) ___ ___,
  ssn ___ ___,
  phone_no ___(___)
);
Edit and Run Code