Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Trigger, change values

Status
Not open for further replies.

mcneija

Programmer
Aug 12, 2003
1
0
0
CA
I need to add a trigger to a table so that if a user submits an isert and forgets a foreign key field, I will go out and find a vlaid value and add it to their insert statement. So I think this has to happen before the insert, but then what? How do I change the values in the insert stmt before they are inserted?
 
If you are using ASA, your trigger will look something like this:
Code:
create trigger tbi_DefaultMyTableFK
before insert on MyTable
referencing NEW as new_rows
for each row
begin
  if MyFKField is null then
    //logic to set FKField default value...
    select max(PKField) 
      into new_rows.FKField
    from MyParentTable;
  end if;
end;

ASE may support something similar, but the syntax will differ.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top