Home › Interview Questions › How does hashing work, and how would you store the…

How does hashing work, and how would you store the hash value in a database column?

🟡 Medium Conceptual Junior level
1Times asked
Nov 2026Last seen
Nov 2026First seen

💡 Model Answer

Hashing is a one‑way function that maps arbitrary data to a fixed‑size string of bytes. In databases, you typically compute the hash of a row or a key column and store it in a dedicated column (e.g., row_hash). This allows quick equality checks and change detection without scanning the entire row. To store the hash, add a new column of type CHAR(32) for MD5, CHAR(40) for SHA‑1, or CHAR(64) for SHA‑256. Compute the hash in application code or via a database trigger, and insert it alongside the original data. Index the hash column if you need to query by it. When you need to compare two rows, you can simply compare the hash values; if they match, the rows are identical (assuming no collision). If you need to detect changes, recompute the hash and compare it to the stored value. This approach reduces I/O and CPU compared to full row comparison.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500