Question

In: Computer Science

I have tables student, professor, and person. The relationship between student and person, and professor and...

I have tables student, professor, and person. The relationship between student and person, and professor and person is Is A inheritance. A person may be a student but not a professor, a professor but not a student, or neither a professor or a student. How do I write a trigger in SQL that forces the constraint that a person cannot be a student and a professor.

Some extra info:

I have defined ID to be PK of person. ID is also PK of professor and student as a FK (for the inheritance)

Solutions

Expert Solution

from the given data the code to create a trigger in SQL is:

first, to create a trigger the syntax is

CREATE TRIGGER [trigger_name] -------------> this indicates the triiger name
[before | after] -------------> this explains about the execution of trigger
{insert | update | delete} -----> this explains about the operations in DML.
on [table_name] ------> this explains about the table name that conneted with the trigger.
[for each row] -----> this explains the tirgger that executes in each row.
[trigger_body] ------> this explains about the operation that performs when trigger is fried.


now from the given data, the tables are student, professor, and person.
next, the relationship between the student and person, and professor and person is inheritance
next A person can be a student but not a professor, a professor but not a student, neither professor nor a student.

next given that,
Person ID is the primary key in the person table.
Professor ID is the primary key in the professor's table.
student as a foreign key for inheritance.

now the trigger in SQL that forces the constraint that a person cannot be a student and a professor is:



CREATE TRIGGER Person
AFTER INSERT, UPDATE
AS
IF EXISTS (
SELECT *
FROM Professor AS P
INNER JOIN (
SELECT Professor_ID, COUNT(*) AS Person_ID
FROM Person
GROUP
BY Professor_ID
) AS R
ON R.Professor_ID ≠ P.Professor_ID
AND P.Person_ID ≠ R.Person_ID
)
BEGIN
RAISERROR ('A PERSON CANNOT BE A STUDENT AND A PROFESSOR);
ROLLBACK TRANSACTION;
RETURN
END;


Related Solutions

Database Design Design a database and show the relationship between each tables. I need multiple tables....
Database Design Design a database and show the relationship between each tables. I need multiple tables. *Must meet the requirements for Third Normal Form. These are the information for employee DB. Employee Number, First Name, Last Name, Date of birth, Address, city, state, zip, department, job title, supervisor, health insurance number, health insurance provider, dental insurance number, dental insurance provider, spouse/partner, children, children's ages.
In C# Create classes: Person, Student, Employee, Professor, Staff and Address ☐ Address class must have...
In C# Create classes: Person, Student, Employee, Professor, Staff and Address ☐ Address class must have suitable auto-implemented properties for Address 1, Address 2 and City. ☐ Person class must have suitable auto-implemented properties for Name, Residence (type Address) and email. ☐ Student and Employee must be subclasses of Person. ☐ Employee must be a super class for Professor and Staff. ☐ Employee class must have suitable auto-implemented properties for salary (between 2000 to 8000), and hire date. ☐ Professor...
A professor is studying to see if there is a relationship between the grades and gender...
A professor is studying to see if there is a relationship between the grades and gender of his students. He picks a random sample of his students and notes their grades (A, B, or C) and their gender (male or female). He finds that: 28% are A students. 58% are B students. 62% of his students are female. Of those who are female, one-third are A students. Of those who are B students, three-fifths are female students. What percentage of...
A professor is studying to see if there is a relationship between the grades and gender...
A professor is studying to see if there is a relationship between the grades and gender of his students. He picks a random sample of his students and notes their grades (A, B, or C) and their gender (male or female). He finds that: 28% are A students. 58% are B students. 62% of his students are female. Of those who are female, one-third are A students. Of those who are B students, three-fifths are female students. What percentage of...
Imagine a professor wants to examine if there is a relationship between gender and performance on...
Imagine a professor wants to examine if there is a relationship between gender and performance on a writing test. Thirty girls and thirty boys participated in his experiment. They were given a standard writing test and their grades were given as “outstanding”, “good”, “passing”, and “failing”. If the professor decided to use a Chi-square test to examine the relationship, how many degrees of freedom are there in this Chi-square test? When using the Chi-square test, the probability of Type I...
A professor of Education is interested in the relationship between students' visits to office hours held...
A professor of Education is interested in the relationship between students' visits to office hours held by professors (online or in person) and students' final grades in the course. She has obtained voluminous data from Hardnocks University regarding these two variables. These data are cross-tabulated below. Visits during Office Hours Grade None One or Two Three or More C or worse 527 520 418 B 527 526 465 A 480 480 500 Total 1534 1526 1383 She hypothesizes that the...
A marketing professor at Givens College is interested in the relationship between hours spent studying and...
A marketing professor at Givens College is interested in the relationship between hours spent studying and total points earned in a course. Data collected on 10 students who took the course last quarter are in file HoursPts.xlsx. Hours Points 45 40 30 35 90 75 60 65 105 90 65 50 90 90 80 80 55 45 75 65 a) Use XLSTAT to create a scatterplot with hours spent studying on the horizontal axis and total points earned on the...
A marketing professor at Givens College is interested in the relationship between hours spent studying and...
A marketing professor at Givens College is interested in the relationship between hours spent studying and total points earned in a course. Data collected on 10 students who took the course last quarter follow. Hours Spent Studying Total Points Earned 45 40 30 35 90 75 60 65 105 90 65 50 90 90 80 80 55 45 75 65 (a) Develop an estimated regression equation showing how total points earned can be predicted from hours spent studying. (Round your...
At the conclusion of this chapter, the student should be able to: Describe the relationship between...
At the conclusion of this chapter, the student should be able to: Describe the relationship between the skeletal muscle’s fiber arrangement and its function.
A psychology professor is interested in the relationship between his students’ performance on two separate quizzes...
A psychology professor is interested in the relationship between his students’ performance on two separate quizzes from his research methods course. He looks at the quiz scores for 16 different students, and notes each student's scores on the two quizzes (where each quiz was based on a 30-point scale). If you wanted to test the hypothesis to see if there was any linear relationship between these two quantitative variables, what would be the appropriate analysis? What would be the null...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT