1

In a relational database, if there is a Student table and Employee table, and a third table StudentAsst who indicates a multiple inheritance from both Student and Employee tables.

My Question: in SQL how to create the StudentAsst, and what is its primary key?

2
  • Databases don't have inheritance, multiple or otherwise. Each table is independent. Commented Jun 1, 2013 at 7:03
  • what are the relations? employee to student, student to asst, employee to asst ? (one to many etc) Commented Jun 1, 2013 at 7:06

1 Answer 1

1

Since a StudentAsst is-a Student and is-an Employee, your table could have a primary key consisting of EmployeeID and StudentID:

CREATE TABLE StudentAsst
(StudentID int, 
 EmployeeID int,
 ...,
 CONSTRAINT PK_StudentAsst PRIMARY KEY (StudentID, EmployeeID),
 CONSTRAINT FK_Employee FOREIGN KEY (EmployeeId)
            REFERENCES Employee(EmployeeID),
 CONSTRAINT FK_Student FOREIGN KEY (StudentID)
            REFERENCES Student(StudentID)
 )

Here is an example of a similar situation with Student, Teachers and Parents.

Sign up to request clarification or add additional context in comments.

1 Comment

I should add as a note that even though this might answer your question, you should ask yourself why you need the StudentAsst table. If there are no fields unique to a student assistant, it would be easier to have foreign key from your Student table to the Employee table, indicating that a student is also an employee.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.