Dynamically update rows in 2 different tables, based on a column??

  • Hey folks! Hopefully you can shed some light. I think I am going to need to write a trigger, but this is kinda new to me. I have been doing some reading, but am not sure where to start. I need to set up something that will automatically update a column in one table, based on my changing a column in another.

    The setup is this. I have a table that is setup to list an individual event and all of the information about this event. Then under that I have a table that lists all of the registrations linked to that event. Under that I have seats linked to that event OR registration. 3 Tables. I would like to update a status field in the Event table, and have all of the registrations and seats that are associated with the event automatically set their status also. This would be on an update of the event, not on the creation of the event.

    The registration has a field labeled new_eventid that has the UID for the event stored in it. The seat has the same thing. That is how they are linked. Where can I start in order to make it so??? Thanks guys!

  • Mike Menser (4/18/2008)


    Hey folks! Hopefully you can shed some light. I think I am going to need to write a trigger, but this is kinda new to me. I have been doing some reading, but am not sure where to start. I need to set up something that will automatically update a column in one table, based on my changing a column in another.

    The setup is this. I have a table that is setup to list an individual event and all of the information about this event. Then under that I have a table that lists all of the registrations linked to that event. Under that I have seats linked to that event OR registration. 3 Tables. I would like to update a status field in the Event table, and have all of the registrations and seats that are associated with the event automatically set their status also. This would be on an update of the event, not on the creation of the event.

    The registration has a field labeled new_eventid that has the UID for the event stored in it. The seat has the same thing. That is how they are linked. Where can I start in order to make it so??? Thanks guys!

    Mike,

    Rather than use a status field in your Registrations and Seats tables, I would just use a query or view and join these tables to your Events table and reference the Events.status field -- you can alias it as registration_status or seat_status if you wish.

    If you really want to store the status in the Registrations and Seats tables, you might want to use computed columns and just reference the Events.status field, but again, really not necessary as you should be able to do with a view/query.

    I would avoid triggers if possible, and I really would discourage using triggers here; I just don't think it's necessary.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply