Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Creating a trigger that will increment a column in one table after an insert has been made in another table

$
0
0

I want to create a trigger that will increment a number in one column of a certain table after an insertion has been made in a different table. 

For Example:

I have an Employees table that has a column entitled DaysAbsent (int). This column provides the number of days an employee has been out. 

I also have a Sick_Days table that logs the Employee, Reason, and Date for each employee who has been absent. 

I want to create a trigger that will increment the number of days absent in the Employees table once a log/insertion has been made in the sick days table. In other words, once an employee has been logged in the Employee Sick Days table, their number of Days Absent will increment in the Employee Table. 

I have been researching online and have started the statement like this:

CREATE TRIGGER IncrementSickDays
ON Sick_Days
AFTER INSERT

Am I on the right track? Any help would be appreciated! Thank you!







Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>