We have an sql-table with products in it.
We need to know how a certain column is mutated, since we made this impossible but it still does get changed.
So say product 'APPLETREE' is once created with length 3 mtr.
This 3 mtr may never be changed. And still sometimes it does get!
To find out why we created a trigger on table products to write a log-file with columns
productnr , oldlength value, newlength value, date, time, user.
This all works fine. We get the info.
But preferably we would also know where the trigger got fired from (which stored procedure or sql job)
Is there a way to get the 'path' from which te trigger was fired ?
I could not find documentation about this
Related
So I am not positive I am even asking the correct question, but here it goes. I currently have a MS Access Form built so that someone can enter in a new work order. You are able to set the company, the part number wanted, quantity, and the Work Order number is an auto generated value that I use for my primary key. All of that works great and successfully adds a new row to the table "Work Orders". However, when this form is used to create a new work order I want the last field in the table "Work Orders" which is called "Status" to be set to "Not Started".
I successfully made an update query that asks for the Work Order Number, and will set the "Status" field to "Not Started". Here is the code for that:
UPDATE 03A_WorkOrderList
SET 03A_WorkOrderList.Status = "Not Started"
WHERE ((([03A_WorkOrderList].WO_Num)=[WO_Num:]));
If you give the update query work order number everything works great and the "Status" field is updated.
So back to the form I decided to attach the update query to the build event where the update happens after the new line is created. That seems to have worked too except it asks for the work order number. I totally understand why because it is the code that is in the update query of : WHERE ((([03A_WorkOrderList].WO_Num)=[WO_Num:]));
What I cannot figure out is how to have it pull the work order number that was automatically generated and use that for the update query.
If I am going about this all wrong, please let me know. TIA.
In Ms Access, open your [Work order] table in design mode. Select the Status field and in the property section below, you can set the Default value to be Not started. This way you don't need to perform an update and all new orders will automatically have Not started status.
or in your add order form, On before update event, you can set the status = 'Not started'
I was able to get the functionality that I was looking for with the following UPDATE Query:
UPDATE 03A_WorkOrderList SET 03A_WorkOrderList.Status = "Not Started"
WHERE [03A_WorkOrderList].WO_Num=(SELECT MAX(WO_Num) FROM 03A_WorkOrderList);
Since the WO_Num is auto generated and I want to edit the very same one I was working on, I could just look for the MAX(WO_Num). I then made this UPDATE query apart of the build event of the order form.
Good evening!
At this moment I'm working on page in the Oracle Apex Application, which works the following way. This is the page, which contains some kind of big and complex report with data differentiated by one feature (let it be named feature A). On the left side of the page there is a "catalog menu", due to which user can see the data answering to feature A, on the right side the data is shown and above there is a the search bar, which can help users to find some exact data by other features feature B, feature C etc.
I had a view (let it be named V_REPORT_BIG_DATA) for showing the report, but it was so big and was loading so slow, that I've decided to switch the page on the table with the same fields as V_REPORT_BIG_DATA (let it be named T_REPORT_BIG_DATA_TEMP). Besides, it has the additional field for process identificator (let it be named PID) and is temporary not physically, but by its purpose. I thought that it must work this way: user enters the page, receives his own PID relevant to the session (it works if PID is null, otherwise it doesn't change), and then the procedure (P_REPORT_BIG_DATA_RELOAD) makes the deleting of the "old" data and uploading of the "new" one, besides these actions are executed with the one PID and are concerned to definite (say, current) user.
But my idea didn't appear to work correct. The procedure P_REPORT_BIG_DATA_RELOAD itself works fine and is executed from the Process page, and PID is a global Application Item (it is generated from a database sequence). But my brain has nearly been blown up when I saw that my table has duplicates of data concerned to one user and one PID! By making the table of logs (which has been filled with the facts, how much rows had been deleted and inserted again, in the code of P_REPORT_BIG_DATA_RELOAD) I saw very strange thing: some users "loaded" duplicates as if the uploading procedure had been executed several times simultaneously!
Taking into account all I've said before, I have the following question: what do I do wrong? What should I do, so that I wouldn't have to use the word "distinct" in the query from the table T_REPORT_BIG_DATA_TEMP?
UPD: Additional facts to my question. Excuse me for my inattention, because I thought that there I cannot edit my first posts. :-/
Well, I'll explain my problem further. :) Firstly, I did all the best for my view P_REPORT_BIG_DATA_RELOAD to expect its loading much faster, but it involves many-many rows. Secondly, the code executed from the Process Page (say, during the loading of my page) is this:
begin
if :PID is null then
:PID := NEW_PID;
end if;
P_REPORT_BIG_DATA_RELOAD(AUTH => :SUSER, PID => :PID);
end;
NEW_PID is a function which generates new PID, and P_REPORT_BIG_DATA_RELOAD is my procedure which refresh the data depending on user and his PID.
and the code of my procedure is this:
procedure P_REPORT_BIG_DATA_RELOAD
(AUTH in varchar2, PID in number)
is
NCOUNT_DELETED number;
NCOUNT_INSERTED number;
begin
--first of all I check that both parameters are not null - let me omit this part
--I find the count of data to be deleted (for debug only)
select count(*)
into NCOUNT_DELETED
from T_REPORT_BIG_DATA_TEMP T
where T.AUTHID = AUTH
and T.PID = P_REPORT_BIG_DATA_RELOAD.PID;
--I delete "old" data
delete from T_REPORT_BIG_DATA_TEMP T
where T.AUTHID = AUTH
and T.PID = P_REPORT_BIG_DATA_RELOAD.PID;
--I upload "new" one
insert into T_REPORT_BIG_DATA_TEMP
select V.*, PID from
(select S.* from V_REPORT_BIG_DATA S
where S.AUTHID = AUTH);
--I find the count of uploaded data (for debug only)
NCOUNT_INSERTED := SQL%ROWCOUNT;
--I write the logs (for debug only)
insert into T_REPORT_BIG_DATA_TEMP_LG(AUTHID,PID,INS_CNT,DLD_CNT,WHEN)
values(AUTH,PID,NCOUNT_INSERTED,NCOUNT_DELETED,sysdate);
end P_REPORT_BIG_DATA_RELOAD;
And one more fact: I tried to turn :PID into Page Item, but it cleared after every refresh in spite of that the option Maintain session state is Per session, so that I couldn't even hope for using the same PID by every definite user in definite session.
A coworker in accounting was complaining about how she ran a query twice and it doubled her values and she got confused. Im just a Junior IT person who has very little VBA experience. I am basically just trying to add code to make it so my queries in our databases can't be run more than once unless you restart the database. I was thinking of doing a boolean check to see if a query has been run and if it has don't allow it to be run again. Or maybe I could just do a simple if statement. Please let me know if you have any input on this issue.
I couldn't find anything on the Googs either.
I would think on a date and a session ID as default values in each table, you could code the addition of both etc.
These are populated, date =date() as default value and sessionID is the DMAX from your SessionID table, as extra column in said query.
This SessionID table is incemented by a startup popup form, running macro.
The Primary Key of each table being operated on would be the date and the sessionID not allowing dupes. You probably dont need the date, just a sessionID in the PK.
It is not always the best idea to implement ad-hoc ideas by users like this.
You should analyze what happened here, and make sure it cannot happen in the application design, not by arbitrary rules.
Example: If the update query adds fees to a bill, and this must happen only once per bill, then the update query should also set a flag "fees added" in the bill record. And it should not update bills with this flag set.
I'm working on a stored procedure, see my last question that explains what I want.
I've created a sproc that adds a movie to the database, and runs separate sprocs from within to create for example a cast for the movie and adds a genre to it (stored in a separate table).
When running the sproc "NewMovie" a new movie gets added to the database, and the ID of that movie is used in the two other sprocs that I run after the movie is added. The problem is that after for example the cast is created, ##IDENTITY refers to CastID, but I need to use the movie ID again after this.
Is it some way that I can get the next latest created ID, or how could I accomplish what I want?
The code so far can be found here if someone has the time to look through it.
Thanks in advance!
Out of curiosity, you already have #MovieID in usp_NewMovie - why not just use that as a parameter to usp_AddGenre and usp_AddMovieRole?
Also you might be better off using SCOPE_IDENTITY() instead of ##IDENTITY http://blog.sqlauthority.com/2007/03/25/sql-server-identity-vs-scope_identity-vs-ident_current-retrieve-last-inserted-identity-of-record/
I made some updates to your code here: http://pastebin.com/rhhrGsuB
What do I gain by adding a timestamp column called recordversion to a table in ms-sql?
You can use that column to make sure your users don't overwrite data from another user.
Lets say user A pulls up record 1 and at the same time user B pulls up record 1. User A edits the record and saves it. 5 minutes later, User B edits the record - but doesn't know about user A's changes. When he saves his changes, you use the recordversion column in your update where clause which will prevent User B from overwriting what User A did. You could detect this invalid condition and throw some kind of data out of date error.
Nothing that I'm aware of, or that Google seems to find quickly.
You con't get anything inherent by using that name for a column. Sure, you can create a column and do the record versioning as described in the next response, but there's nothing special about the column name. You could call the column anything you want and do versioning, and you could call any column RecordVersion and nothing special would happen.
Timestamp is mainly used for replication. I have also used it successfully to determine if the data has been updated since the last feed to the client (when I needed to send a delta feed) and thus pick out only the records which have changed since then. This does require having another table that stores the values of the timestamp (in a varbinary field) at the time you run the report so you can use it compare on the next run.
If you think that timestamp is recording the date or time of the last update, it does not do that, you would need dateTime fields and constraints (To get the orginal datetime)and triggers (to update) to store that information.
Also, keep in mind if you want to keep track of your data, it's a good idea to add these four columns to every table:
CreatedBy(varchar) | CreatedOn(date) | ModifiedBy(varchar) | ModifiedOn(date)
While it doesn't give you full history, it lets you know who and when created an entry, and who and when last modified it. Those 4 columns create pretty powerful tracking abilities without any serious overhead to your DB.
Obviously, you could create a full-blown logging system that tracks every change and gives you full-blown history, but that's not the solution for the issue I think you are proposing.