clear markdown compare help best fiddles feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3601491 fiddles created (47963 in the last week).

CREATE TABLE T1 (ID int); CREATE TABLE T2 (ID int); CREATE TABLE T3 (ID int); CREATE TABLE T4 (ID int);
 hidden batch(es)


INSERT INTO T1 VALUES (1),(2),(3),(4); INSERT INTO T2 VALUES (4),(6); INSERT INTO T3 VALUES (4),(5); INSERT INTO T4 VALUES (4),(5),(6);
11 rows affected
 hidden batch(es)


CREATE TRIGGER t1_insert ON T1 AFTER INSERT AS BEGIN IF EXISTS(SELECT 1 FROM inserted JOIN ( SELECT ID FROM T2 UNION ALL SELECT ID FROM T3 UNION ALL SELECT ID FROM T4 ) others ON others.ID = inserted.ID) BEGIN PRINT 'YES'; END ELSE BEGIN PRINT 'NO'; END END
 hidden batch(es)


INSERT INTO T1 VALUES (5);
YES 1 rows affected
 hidden batch(es)


INSERT INTO T1 VALUES (7);
NO 1 rows affected
 hidden batch(es)