SQL, Compare then update a field after insertion
I have two tables in SQL: tbl_names, and tbl_insert.
the field named: tbl_names.field_dictionary contains names.
the tbl_insert contains many fields and one of them is called tbl_insert.field_keywords and another 2 fields called tbl_insert.field_title and tbl_insert.field_details.
now my question is the following:
I need a stored procedure code to tell sql every time I insert a record in tbl_insert i want the sql to compare tbl_names.field_dictionary against tbl_insert.field_title and tbl_insert.field_details ; if those two fields contains the keywords listed in tbl_names.field_dictionary; i need to insert/update the field named: tbl_insert.field_keywords by inserting only the founded keywords inside the tbl_names.field_dictionary into the tbl_insert.field_keywords without repeating the words found inside the field.
I hope someone can help me in providing me with this code, take it as a challange.
Re: SQL, Compare then update a field after insertion
You can compare by using before insert trigger, by putting your stored procedure code inside the trigger on table tbl_insert. Even you can use after insert trigger, check the content of inserted value with field_dictionary of the tbl_names table, if it is matching, commit the changes else rollback.