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