140k views
2 votes
Two tables are created:

1- Horse with columns:

ID - integer, primary key

RegisteredName - variable-length string

2-Student with columns:

ID - integer, primary key

FirstName - variable-length string

LastName - variable-length string

Create the LessonSchedule table with columns:

HorseID - integer with range 0 to 65 thousand, not NULL, partial primary key, foreign key references Horse(ID)

StudentID - integer with range 0 to 65 thousand, foreign key references Student(ID)

LessonDateTime - date/time, not NULL, partial primary key

If a row is deleted from Horse, the rows with the same horse ID should be deleted from LessonSchedule automatically. If a row is deleted from Student, the same student IDs should be set to NULL in LessonSchedule automatically. Note: Table and column names are case sensitive in the auto-grader.

2 Answers

3 votes

Final answer:

The question is about creating a LessonSchedule table with specific columns and constraints in the Computers and Technology subject.

Step-by-step explanation:

The subject of this question is Computers and Technology. The question is asking to create a LessonSchedule table with specific columns and constraints.

The LessonSchedule table should have three columns: HorseID, StudentID, and LessonDateTime. The HorseID column should have a range from 0 to 65 thousand, be not NULL, and serve as a partial primary key, referencing the ID column in the Horse table. The StudentID column should have a range from 0 to 65 thousand and reference the ID column in the Student table. The LessonDateTime column should be not NULL and also serve as a partial primary key.

User Nightcrawler
by
8.3k points
1 vote

The SQL code to make the LessonSchedule table with the given requirements is shown below:

CREATE TABLE Horse (

ID INT PRIMARY KEY,

RegisteredName V/A/R/C/H/A/R(255) -- Adjust the length as needed

);

CREATE TABLE Student (

ID INT PRIMARY KEY,

FirstName V/A/R/C/H/A/R(255),

LastName V/A/R/C/H/A/R(255)

);

CREATE TABLE LessonSchedule (

HorseID INT NOT NULL,

StudentID INT,

LessonDateTime DATETIME NOT NULL,

PRIMARY KEY (HorseID, LessonDateTime),

FOREIGN KEY (HorseID) REFERENCES Horse(ID) ON DELETE CASCADE,

FOREIGN KEY (StudentID) REFERENCES Student(ID) ON DELETE SET NULL

);

The SQL code above is one that makes three tables: Horse, Student, and LessonSchedule.

HorseID is known to be an integer that references the ID of the horse associated with the lesson. So, to use the above code, one need toa adjust the data types and lengths based on their own specific requirements.

Note, var was separated with "/" because it is showing inappropriate word

User Grenade
by
8.5k points