SQL to create a Trigger for MySQL

weklica used Ask the Experts™
I have a  MySQL database with a date field.  I want a Trigger to pull the Weekday word out of that value and place it into another field on record creation.  I am not finding a sample of how to do so in my hunting around.  Any thoughts?  Thanks much.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DISCLAIMER FIRST: I not much of MySQL guy and shouldn't technically be posting a comment here.

Your usage of word trigger and the requirement doesn't really jell together with respect to database nomenclature hence the comment. Can you possibly share some mock table structure, sample data and what you are expecting as output and / or expect to see happening.

Such an information would potentially also be helpful to any other MySQL expert attempting to understand / answer your question.


Basically, I have a timestamp as one field.  I have another 'Weekday' field that is currently NULL.  But, upon insertion of a new record, the timestamp field is always populated.  I would like to have the Weekday name pulled from that timestamp field and inserted into the 'Weekday' field automatically.  I re-read my initial post and agree it didn't quite sound detailed enough.
First it is not clear where you are stuck. Is it pulling weekday from the timestamp or writing a trigger. Either of which can be done with a bit of a help from Google.

Second, assuming you determine how to arrive at Weekday from timestamp, why would you have it persisted in a table and waste storage. It can very well be achieved by just adding one column at the time of select or better still have a view which does the job and use it.

I would discourage you to store something which can easily be arrived at from the value of another column.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial