cmcculloh web design
cmcculloh.com - Personal - Tutorials - SQL Lectures - 2.14.06: Relational Databases - Create Favorite Foods Table

Create Favorite Foods Table

Michael Xue
Christopher McCulloh
2.14.06

Valid XHTML 1.0 Strict

We are going to call it "favorite_food" it will have the following values:

person_id int,
food varchar(20),

Now we will specify the primary key, which is the combination of the two columns

person_id int,
food varchar(20),
constraint pk_favorite_food
primary key(person_id, food)

Neat. So that mixes the two columns together to create a primary key. Now lets make the foreign key work

person_id int,
food varchar(20),
constraint pk_favorite_food
primary key(person_id, food),
constraint fk_person_id
foreign key(person_id)
references person(person_id)

ok, so now you make it into SQL code: