Results 1 to 7 of 7

Thread: INSERT Trigger Help

  1. #1
    Join Date
    Feb 2006

    Unhappy INSERT Trigger Help

    Hello. I'm new to Triggers, but based on my design, it seems like I need to get familiar.

    Here's the scenario. Three related tables.

    tblCap - capID, etc.
    tblBU - buID, busUnit, etc.
    tblCapBuMap - fk_capID, fk_buID, isPrimary

    tblCap holds information about trouble ticket escalations, tblBU is a lookup table that contains business units that the trouble ticket can be assigned to (no limit). tblCapBuMap is a map table that will contain which business units are attached to a particular trouble ticket.

    What I would like to accomplish is upon inserting a new record in tblCap, I would like to create new records in tblCapBuMap representing all business units (all records in tblBU).

    Likewise, when inserting a new record in tblBU, I would need to create a new record in tblCapBuMap for every open record in tblCap.

    I've looked through some trigger examples, but most examples don't seem to be anywhere near this complicated and thus I've got no idea where to turn.

    Any help would be greatly appreciated!!


  2. #2
    Join Date
    Aug 2005
    The Garden State
    it really comes down to what you're going to be putting in there. what data's going in the table, what's going into the other tables, etc.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Feb 2006
    Thanks for the reply.

    The Cap table has information on the details of the escalation. The BU table is just a lookup table containing business Units (Marketing, Sales, etc.). So, when a new record is entered into tblCap, I would like the trigger to insert a record into tblCapBuMap that contains the new escaltions id (capID) and the key for the business units.


    New record gets inserted into tblCap

    INSERT INTO tblCap (customer, dateOpened, caseStatus)
    VALUES (Barney's, 11/05/2005, Open)

    Once inserted, initiate trigger/cursor to create a record in tblCapBuMap for the new escalation and each business unit:


    INSERT INTO tblCapBuMap (fk_capID, fk_buID, isPrimary)
    VALUES (21, 4554, 0)

    for each record in tblBU, so the tables would look like the following:
    capID Customer dateOpened caseStatus
    21 Barney's 11/05/2005 Open

    buID busUnit
    4550 Marketing
    4551 Sales
    4552 Accounting
    4554 Human Resources

    fk_capID fk_buID isPrimary
    21 4550 0
    21 4551 0
    21 4552 0
    21 4553 0
    21 4554 0

    Now that there would be corresponding records for every BU to each Cap, you can go in and set them as active by using the isPrimary field.

    Does this make sense?

    Thanks again!

  4. #4
    Join Date
    Aug 2005
    The Garden State
    what dbms are you using? trigger syntax differs from oracle, ms sql, etc.

    the problem is that how do you know who's getting assigned what? if you only do an insert on one table, it can't see what you just inserted into another table. I don't see any relation between tblCap and tblBU aside from tblCapBUMap. It might be better to do this via a stored procedure.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  5. #5
    Join Date
    Feb 2006

    I'm using MS SQL2000.

    There's no relation from tblCap to tblBU outside of the map table. At the point of entry of the new record in tblCap there may not be a business unit assigned, so there's no need to actually know at this point. The purpose is to have the records in the map table, so that when the user goes in to assign the business units, the relationship/records exist in the map table. The user simply "activates" the business unit in the map table via a form.


  6. #6
    Join Date
    Aug 2005
    The Garden State
    unfortunately, I do not know ms sql server well enough to answer this. Here's a link @ this site's sister about creating ms sql server triggers:

    as for what you're doing, do you really need to have a separate table? it's a 1:1 correspondence (1 ticket goes to 1 BU) from what you've shown so you might not need it. all you're doing is inserting the new request id into the other table after insert.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  7. #7
    Join Date
    Feb 2006

    Actually, there is no limit to the number of bu's assigned to a ticket. *It's terrible business rules*, but I don't make those rules, unfortunately. I just have to work around someone else's lazy mind.

    So, one Cap can have eight BUs assigned to it, which is why I went with a map table so, I can create an unlimited amount of flexibility. The rules have changed over time. Originally, it started off as 1:1 then morphed to 1:4 and I kluged my way into a solution. Basically, they upped the ante again and I'm tired of programmatic changes because they are slackers, so I want to create a true 1:x relationship.

    Thanks again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.42153 seconds
  • Memory Usage 2,900KB
  • Queries Executed 13 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates