Anyone here who can show me the right direction to achieve the following ? I try to explain it clearly.
Table Aircraft_types has the columns pattern_id, aircraft_id, version_nr, aircraft_class )
When someone insert a new record in this table Aircraft_types, a default record need to be inserted into the same Aircraft_types table.
it's important that this new record has the same value for Aircraft_id and pattern_id. the aircraft_class need to be retrieved from the column Classid from the aircraft_pattern based on the new pattern_id
and it's also important that the default record doesn't need to be created when there is already a record where pattern_id and aircraft_id are identical.
So for example
somene enters the record
pattern_id = BE9M and aircraft_id = P47.
The default record that has to be created is
pattern_id = BE9M
aircraft_id = BE9M
aircraft_class = must contain the value of this select : select aircraft_class from aircraft_patterns where pattern_id = 'BE9M'
I've tried a constraint and a decision ( that is called in the post-insert trigger in the application), but with no success.
the constraint:
INSERT INTO AIRCRAFT_TYPES ( aircraft_id, pattern_id, aircraft_class )
SELECT cap.pattern_id, cap.pattern_id, cap.category
FROM AIRCRAFT_PATTERNS cap
WHERE NOT EXISTS ( SELECT ''
FROM AIRCRAFT_TYPES cat
WHERE cat.version_nr = cap.version_nr
AND cat.pattern_id = cap.pattern_id
AND cat.pattern_id = cat.AIRCRAFT_D)
The deicsion was similar, but then with using the sql-script() function.