(Edited following comments and after checking what INSERTED is in SQL Server)
The INSERTED table in SQL Server represents the rows that were inserted by the triggering statement. Oracle doesn't have this. Instead, a row-level trigger can refer to the column values of each row affected by the trigger, using :new and :old values. (Only :new values are ...
The problem you originally had was that you were not referencing the deleted pseudo-table. You were essentially saying "Oh, delete subcategory 5? Ok, delete all products that have a subcategory!"
I think you want this in your trigger:
FROM dbo.DimProduct AS p
INNER JOIN deleted AS d
ON p.ProductSubcategoryKey = d....
I fear the where clause with the in is causing problems. Try joining to the inserted table instead. Here are two examples - one with the in clause and one with a join to the inserted table. The results are different using my sample data.
drop table if exists shipment;
drop table if exists alphauniversal;
create table SHIPMENT (cm_controllerID int,au ...
We have an application, with an application user needs to be db_owner on the database
If this application is written "in-house" then push back - hard - and get them to justify why this needs to be the case.
Running an application as a database owner, you might as well hand the database back to the Development team because they can do pretty much ...
In addition to the other answer and comments: Your constraint will give you an error message and halt the operation, and the trigger will never fire. Constraints are checked before triggers are fired.
So if you really want to do this then either have a trigger or a constraint. You can of course have a trigger and a disabled constraint (letting the constraint ...
If I understood you correctly, then see if this helps:
select created_date from that table
check if it is lower than previous Sunday's 23:59
why? Because I presume that it can't be created in the future
How to find that moment in time? One option is to use NEXT_DAY function which returns the "next" Sunday, but - if you subtract 7 (days) from it, ...
After Laurenz Albe suggestion of using the AFTER TRIGGER, I revisited the use of it to see why exactly it hadn't worked when I tried it before, and found out that NEW and OLD cannot be used in trigger functions called by an after trigger to modify such values (which is described in the documentation).
So a function that works in a before update trigger will ...
I would recommend using this trigger template where possible. change it to suit your needs, of course.
It uses an IF UPDATE(column) to short circuit if the DML doesn't reference the column the trigger cares about. It also uses the EXCEPT clause for what I've found the fastest way to compare the INSERTED and DELETED tables. Just add more columns to the ...