183k views
2 votes
Create a Trigger statement which will update the athlete_county to be 'US' if it is not included when building the athlete's record through the following view. Athlete View

id name age ... Record Country
1 Mark ... 3.5 US
2 John ... 2.8 US
3 Bob ... 4.7 US
4 Dan ... 4.5 Canada
5 James ... 3.2 Canada
6 Mike ... 2.9 Canada
7 David ... 6.7 Canada

User FeifanZ
by
8.6k points

1 Answer

4 votes

Final answer:

To ensure that the athlete_country is set to 'US' for any new record through a view, you can create a trigger statement that sets the field to 'US' if it is NULL before the actual insert operation takes place.

Step-by-step explanation:

The question involves the creation of a trigger statement within a database system to ensure that the athlete_country field is set to 'US' when data is inserted through a view, if the country is not specified. Here's how you can write such a trigger:

CREATE TRIGGER SetCountryToUS
BEFORE INSERT ON AthleteView
FOR EACH ROW
BEGIN
IF NEW.athlete_country IS NULL THEN
SET NEW.athlete_country = 'US';
END IF;
END;

This SQL trigger will check the 'athlete_country' field before an insert operation on the 'AthleteView'. If the country is not included (NULL), it will set the 'athlete_country' field to 'US'.

User Mangrio
by
9.0k points

No related questions found