Skip to content

Tag: triggers

SQL Trigger – Having one is messing up new SQL queries

I am able to manually execute the following code: However, if I try creating a Trigger with the same code as above, I get this error when creating a new user in my database: Can’t update table ‘members’ in stored function/trigger because it is already used by statement which invoked this sto…

sql prevent double booking with trigger

I am stumbled on constructing a DB table for hotel reservations. In my reservation db, there is a reservation start_datetime and end_datetime attribute to indicate booked period and I tried to prevent double booking with a trigger statemen, but I am certain that this method would be vulnerable to race conditi…

Trigger to create or update records in another table

Edit: This question is mostly solved. What I am still trying to do might require a different approach. I am adding a trigger to a legacy database table, in order to automatically create new records for a related table. This is not homework. Here is my DB Fiddle on SQL Server 2017. https://dbfiddle.uk/?rdbms=s…