coryd.dev/queries/triggers/update_total_plays.sql

30 lines
395 B
SQL

BEGIN
UPDATE artists
SET
total_plays = total_plays + 1
WHERE
name_string = NEW.artist_name;
UPDATE albums
SET
total_plays = total_plays + 1
WHERE
key = NEW.album_key
AND artist_name = NEW.artist_name;
UPDATE genres
SET
total_plays = total_plays + 1
WHERE
id = (
SELECT
genres
FROM
artists
WHERE
name_string = NEW.artist_name
);
RETURN NEW;
END;