Trigger To Update A Field When Field In Another Table Is Changed

I have a mysql database and I want a Trigger To Update A Field When Field In Another Table Is Changed.

Table 1 = cases_cstm and Table 2 = Contracts
I have an End date field in both tables.
The Field name under cases_cstm is enddate_c
The field name under Contracts is end_date

I would like when a Case is created to copy the End date from Contracts to Cases
Pat ShorttManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Review your model. This is redundancy at its best.
0
Pat ShorttManagerAuthor Commented:
I don't understand your comment?
0
ste5anSenior DeveloperCommented:
Normalization. Why copying a value at all? This value should be stored only once.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Pat ShorttManagerAuthor Commented:
Cause I need to display the same date in 2 different views. one in Cases and one in Contracts.
0
pcelbaCommented:
If the date has equal value in all tables involved then it really IS redundancy... If you allow different values for whatever reason then we cannot talk about redundancy.

I just don't understand what is the problem in trigger creation.
Simply create a trigger on "Another table" where the date is updated and update the date field in all your other tables in this trigger.

BUT when you are creating the case then you don't need any trigger to set its initial date value. It has nothing to do with triggers.
0
NerdsOfTechTechnology ScientistCommented:
On inserting a new case, you can SELECT query contracts' end date and insert it into the case record (assuming that it has and ID) via SUBQUERY.

What is confusing is if you are recording the end date of the case separately from the contracts table for whatever reason AND why.

Maybe a question to ask is: if the contracts end date ever changes, are you expecting the cases record(s) to change also? If the contract end date is the accurate value (and a redundancy is present), the solution is simply a LEFT JOIN to contracts to output the correct end date in view(s); thus, in this scenario, make the end_date in cases obsolete/irrelevant/redundant/to-be-deleted. If the end dates are separate, in your current design, the cases' end dates will end up disjointed/non-matching from contracts (where case end dates would become outdated eventually) once contracts' end date is changed... is this expected?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.