|
|
Triggers
There are examples of two very simple statement triggers in the
MIMER_STOREschema, both defined against thePRODUCTStable. They are designed to ensure that the value of thePRODUCT_SEARCHcolumn is based on the product name. The insert trigger unconditionally performs an update of thePRODUCT_SEARCHcolumn (setting it to the default value), which will force the update trigger to fire.The update trigger checks whether the value in the
PRODUCT_SEARCHcolumn is equal to the value returned by thePRODUCT_SEARCH_CODEfunction when applied to the product name. If the value ofPRODUCT_SEARCHis inconsistent with the product name then an update is performed; this will cause a recursive call of the update trigger. Note that an update statement causes the trigger to fire even when no rows are updated, hence the use of 'if exists'.The
PRODUCT_SEARCH_CODEfunction returns the Soundex value of the product name after it has been processed by theINDEX_TEXTfunction, which basically involves stripping out any of the words that appear in theSTOP_WORDStable (i.e. the 100 most common words in the English language). As an example, the album title `Same As It Ever Was' is reduced to `Same Ever' by theINDEX_TEXTfunction and the Soundex value returned by thePRODUCT_SEARCH_CODEfunction would then be `467900'. By using this function against a user input string, it is possible to allow a limited level of fuzzy matching.
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|