I have two tables.
TABLE2 has fields CODE_NM and DESCRIPTION. CODE_NM is the primary key in this table and a foreign key in TABLE1 to this table.
TABLE2:
|---------------------|------------------|
| CODE_NM | DESCRIPTION |
|---------------------|------------------|
| 001 |description 1 text|
|---------------------|------------------|
| 002 |description 2 text|
|---------------------|------------------|
TABLE1:
|---------------------|----------------------|------------------|
| CODE_NM | DESCRIPTION_DETAIL | USER |
|---------------------|----------------------|------------------|
| 001 | some text in here | USERID |
|---------------------|----------------------|------------------|
Every time a row is inserted to TABLE1, a user will input the DESCRIPTION, DESCRIPTION_DETAIL, and USER. With each insert, I want to replace the DESCRIPTION with CODE_NM instead. It is certain that for any DESCRIPTION inserted, there will be a value for it with its associated primary key in TABLE2.
So I should be able to insert:
INSERT INTO TABLE1 (CODE_NM, DESCRIPTION_DETAIL, USER)
VALUES ('description 1 text','this it the situation','USERID');
and instead of 'description 1 text', I want to display the primary key, which is '001':
|---------------------|----------------------|------------------|
| CODE_NM | DESCRIPTION_DETAIL | USER |
|---------------------|----------------------|------------------|
| 001 | some text in here | USERID |
|---------------------|----------------------|------------------|
Is this possible to do using a trigger?