Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

trigger and foreign key

ctcurlerctcurler Member Posts: 1
Is there a way to build a trigger (add,update) that will look up a foreign key from a code table? Example - table a has columns genkey and source code, where genkey is a generated key based on a sequence number and source code is some data that the user is expecting. Table b has the column genkey and when data is added,updated need to find genkey value in table a by using source code which is available in the input data. This is for an oracle application.

thanks for any help.

Comments

  • infidelinfidel Member Posts: 2,900
    : Is there a way to build a trigger (add,update) that will look up a foreign key from a code table? Example - table a has columns genkey and source code, where genkey is a generated key based on a sequence number and source code is some data that the user is expecting. Table b has the column genkey and when data is added,updated need to find genkey value in table a by using source code which is available in the input data. This is for an oracle application.

    You don't need a trigger here. The trigger would only fire on an INSERT or UPDATE of table B, which means you'd have to be inserting the data into table B that you need to get the genkey from table A, which would mean table B is not normalized. What you want to do is

    select genkey from A where sourcecode = 'entered value'

    Now you've got genkey to use when you insert or update table B.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.