D
D
dienerie2021-04-22 15:23:46
SQL
dienerie, 2021-04-22 15:23:46

How to set a trigger to change the value in a field when a change is made in another field?

How to set a trigger in Microsoft SQL Server
There are two tables

Table 1 users
id
update

Table 2 routes
user_id (connection to the users table id field)
route

By default, the update field is 0.
If there are any changes in the route, the field update is set to 1
in case it happens

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Akina, 2021-04-22
@Akina

CREATE TRIGGER tr
ON routes
AFTER INSERT 
AS 
UPDATE [user]
SET [update] = 1
FROM INSERTED
WHERE id = INSERTED.user_id;

fiddle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question