From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Create a trigger to add points to player records

Create a trigger to add points to player records - SQL Server Tutorial

From the course: Complete Guide to Advanced SQL Server

Create a trigger to add points to player records

The first task in our Game Score database project is to synchronize the points awarded from our ScoreEvents table, and then add those points to the scores recorded in the Players table. And we can do that with a trigger. And that's what we're asked to create here for this first part. So I'm going to go ahead and get started. I've got my database set up over here and the two tables created from the prior movie. I'm just going to execute the script as we have it here on the screen here, just to take a look at the starting state of both of those tables. So at the top here, we've got the ScoreEvents table. There's no records yet. And this is where we're going to store the score ID, the date that the score was earned, the player that earned those points, as well as the number of points that they earned. And then our trigger that we're about to write is going to take whatever the score is and add it to the player score that's recorded in the Players table. And so that's our goal is to…

Contents