Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.9K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.4K Development
- 17 Developer Projects
- 139 Programming Languages
- 293.1K Development Tools
- 111 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 161 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 475 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Simple Trigger Issue?
Answers
-
Why do you need a trigger and an "audit" table at all? Looks to me like you could just add a status column to your 'consultants' table.
-
This is simply to demonstrate how a trigger can be used so that a consultant must gain approval from an admin.
Consultants are using an apex application to view their own data, and to request a change to either name or postcode.
So it's an admin that allows these by changing the value from Pending to Authorised.
Just for an assignment!
-
JazzyB wrote:This is simply to demonstrate how a trigger can be used so that a consultant must gain approval from an admin.Consultants are using an apex application to view their own data, and to request a change to either name or postcode.So it's an admin that allows these by changing the value from Pending to Authorised.Just for an assignment!
Oh, so the whole thing is a homework question . . . .
-
I honestly tried so many methods I don't remember haha, only been learning SQL just shy of a year so I still make them mistakes.
Basically I want it so that the update will take place on the consultant table once that 'Pending' in the audit table has been changed to 'Authorised'.
At the moment, the consultant's changes are being immediately updated.
So I'm unsure how to do this as the 'Pending' value is in a separate table.
Hope this makes sense!
-
JazzyB wrote:Thanks for the response,It was that semicolon and after INSERT was changed to after UPDATE as I'm attempting to demo on existing dataA silly mistake but now works.I am attempting to only let these changes pass if the status in the audit table is changed to 'Authorised'Is this possible by using an if statement within the trigger?Or does a seperate BEFORE UPDATE trigger need to be made for my consultant table?Thanks again
I don't see how this would work, the update must happen in order for the trigger to fire...
If you want to add an authorization step to updates then you might want to consider:
Create a staging table with the same columns and primary key, add additional column(s) for authorization status (and authorized by person etc)
Create a view on this table which doesn't include authorization columns and also filters out rows that have been authorized. Grant inserts,deletes and select on this view by the users that you don't wish to update the original table directly but do wish to be able to get their changes authorized.
Grant updates to the staging table to users that can authorize, you could use a trigger here if you wanted to make sure that they set an authorized by person to themselves.
Write a procedure that is owned by the owner of the main table that merges into the main table selecting only authorized changes from the staging table, and then deletes the staging rows that were used.
-edit
Or instead of deleting rows from the staging table you can archive them off into an audit table
-
JazzyB wrote:I honestly tried so many methods I don't remember haha, only been learning SQL just shy of a year so I still make them mistakes.Basically I want it so that the update will take place on the consultant table once that 'Pending' in the audit table has been changed to 'Authorised'.At the moment, the consultant's changes are being immediately updated.So I'm unsure how to do this as the 'Pending' value is in a separate table.Hope this makes sense!
So you want to do the update, but have the update float in some limbo somewhere until the audit table is updated?
That's not going to work, certainly not with triggers. The effects of the trigger are part of the same transaction that caused the trigger to fire. All the changes have to be either committed or rolled back together and no other user can see the audit record to approve it until the commit happens.
Look at Andrew's suggestion in reply #15 - you'll need something along those lines, not triggers.
-
Thanks for such an insightful response
I'll look into this and can hopefully get it working
Much appreciated!