Question: What is wrong with my sql syntax? The question: Create a table in database horsestable called lesson_schedule with the following attributes, data types, and constraints:

What is wrong with my sql syntax?

The question:

Create a table in database horsestable called lesson_schedule with the following attributes, data types, and constraints:

a. horse_id, int, not null

b. student_id, int

c. boarder_id int

d. lesson_time timestamp, not null

e. primary key horse_id, lesson_time

f. foreign key, field horse_id, table horse, primary key field

g. foreign key, field student_id, table student, primary key field

h. foreign key, field boarder_id, table boarder, primary key field

Create a table in database horsestable called boarder_horse with the following attributes, data types, and constraints:

a. horse_id, int, not null

b. boarder_id, int

c. primary key horse_id

d. foreign key, field horse_id, table horse, primary key field

e. foreign key, field boarder_id, table boarder, primary key field

My snytax:

create table lesson_schedule(

horse_id int NOT NULL, student_id int, boarder_id int, lesson_time timestamp NOT NULL, PRIMARY KEY(horse_id), FOREIGN KEY(horse_id) references horse(ID), FOREIGN KEY(student_id) references student(student_id), FOREIGN KEY(boarder_id) references boarder(boarder_id) );

create table boarder_horse(

horse_id int NOT NULL, boarder_id int, PRIMARY KEY(horse_id), FOREIGN KEY(horse_id) references horse(ID), FOREIGN KEY(boarder_id) references boarder(boarder_id) );

When I try to enter this into my sql I get the error message "Cannot add foreign key constraint"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!