Question: Can someone explain to me why I'm getting this error? Need help troubleshooting my sql server code for creating a trigger. Is there anything wrong
Can someone explain to me why I'm getting this error? Need help troubleshooting my sql server code for creating a trigger. Is there anything wrong with my syntax based on the error that I'm receiving?
Question:
- Another practical use of a trigger is cross-table validation (that is, the validation needs columns from at least one table external to the table being updated). Create a trigger that blocks a like from being inserted if its liked_on date is before the posts created_on date. Verify the trigger works by inserting two likes one that passes this validation, and one that does not. List out the Likes table after the inserts to show one insert was blocked and the other succeeded.
code:

For reference my Likes table has the following columns:
likes_id, person_id, post_id, liked_on
AND my Post table has the following columns:
post_id, person_id, content, created_on, summary
1 CREATE TRIGGER check_like_trg 2 ON Likes AFTER INSERT 3 AS 4 BEGIN 5 DECLARE @v_liked_on DATE; 6 DECLARE @v_created_on DATE; 7 8 SELECT @v_liked_on=INSERTED liked_on, 9 @v_created_on=INSERTED.created_on FROM Post 11 JOIN INSERTED ON INSERTED.post_id = Post: post_id; 12 IF @v_liked_on
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
