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.
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...
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 sociologist believes that there is a relationship between number of friends an elderly person has...
A sociologist believes that there is a relationship between number of friends an elderly person has and their perceived level of stress. Participant # of Friends (Y) Stress Level (X) A 10 1 B 3 7 C 12 2 D 11 3 E 6 5 F 8 4 G 14 1 H 9 2 I 10 3 J 2 10 *higher scores of the measure of stress (from 1 to 10) indicate more stress. Use this information to answer questions...
A business person is trying to estimate the relationship between the price of good X and...
A business person is trying to estimate the relationship between the price of good X and the sales of good Z of certain groups of staples. Tests in similar cities throughout the country have yielded the data below: PRICE (X)                  SALES (Z)      $15                              3300 $20                              3900 $25                              4750 $30                              5500 $40                              6550 $50                              7250 A simple linear regression of a model SALES (Z) = b + b PRICE(X) Was run and the computer output is shown below: PRICE OF X...
A researcher investigates whether there is a relationship between the number of cigarettes a person smokes...
A researcher investigates whether there is a relationship between the number of cigarettes a person smokes and whether the person wears a seat belt when driving. His thinking is that people who smoke more are less concerned about their health and safety and therefore may be less inclined to wear seat belts. He collects the following data: Number of Cigarettes Smoked per Day                                                 0          1-14        15-34            35 and over             ----------------------------------------------------------------------------             Wear seat belts            175        20           42                 41             Don’t wear seat belts  150        17           53                 64 At a 0.01 significance level test...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT