Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6357843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:15:00+00:00 2026-05-24T23:15:00+00:00

I am struggeling to create a trigger within MySQL, so that everytime I am

  • 0

I am struggeling to create a trigger within MySQL, so that everytime I am inserting a value into a column named title a HASH shall be created and stored in the column title_hash. Since I don’t know how this works I found this code while googling:

CREATE TRIGGER insertModelHash
BEFORE
  INSERT
ON
  products
FOR EACH ROW SET
  NEW.model_hash = CONV(RIGHT(MD5(NEW.products_model), 16), 16, 10)

The MySQL-reference tells me, that this means:

  1. Create a trigger called insertModelHash…
  2. … before inserting row int table products…
  3. use the functions MD5, RIGHT, CONV on the column products_model in every new row I intend to insert.

The 3. point needs more explanation:

  • I guess, that NEW is some sort of identifier of new rows. So NEW.products_model points to the column products_model in the current (new) row.
  • Then MD5 is issued. Since I want to use SHA-2 it is obvious for me to change MD5(NEW.products_model), 16) ===> SHA2(NEW.products_model), 224).
  • And now I struggle: Why does this guy use CONV(RIGHT(...)...)? Is this really necessary?

Additional information: Right now, I am doing

hashlib.sha224(title).hexdigest()

in Python and store this value.

I appreciate any suggestions/explanations!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:15:01+00:00Added an answer on May 24, 2026 at 11:15 pm

    To answer your three questions:

    The NEW keyword references the ‘pseudo-table’ for the record that would be inserted. On an updated trigger, you can access both ‘NEW’ and ‘OLD’, and on a delete, just ‘OLD’.

    Yes, MD5 is used to create the hash. However, in your question, you have part of the parameter to the ‘RIGHT’ function included. It’s only MD5(NEW.products_model) (there’s no , 16). And yes, you can substitute SHA2 for MD5, if it’s available (it’s only available if MySQL is configured for SSL support).

    The RIGHT(string, number) simply takes the right ‘number’ characters from ‘string’.
    The CONV() function is used to convert a number between bases. The combination of these last two functions takes the right 16 characters of the hash, and converts them from base 16 (hex) to base 10 (decimal).

    And the answer is no, you don’t need them if all you want to do is store the hash itself.

      NEW.model_hash = SHA2(NEW.products_model)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys I need to create a trigger in ORACLE 10g which ensures that
I'm struggling to create a table view controller that has anything more than just
I'm struggling to create a custom UITableViewCell (in IB) that has a UIImageView on
I'm using mysql to create an hotel booking system, but i am struggling a
I've been struggling to create a form for a Mongoid model that has an
as the title suggests, I'm struggling to understand how to create a new table
I am struggling to find a way to create the Forms functionality that I
Appearance-wise, I am struggling to use CSS to create buttons for forms that will
As MySQL-Noob I am struggeling to solve the following task: Assuming 3 tables: location
I'm struggling to create a search that searches for multiple words. My first attempt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.