E
E
Ellik2015-11-10 12:38:24
MySQL
Ellik, 2015-11-10 12:38:24

How to create a unique field of type TEXT?

There are no problems with the varchar type. Set a unique value. But what if you need to store a unique value of type TEXT

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Chernousov, 2015-11-10
@Ellik

Hang up an additional field of type varchar, set it unique and create a trigger that works on insert / update which calculates md5 for the text field and writes it to the varchar field. The trigger executes before writing or updating. If the md5 matched, then the text matched, and this will throw an exception.
Sobsno that's the whole focus.

L
LittleFatNinja, 2015-11-10
@LittleFatNinja

no way. and why is that at all?

O
Optimus, 2015-11-10
Pyan @marrk2

Do you want that there are no two identical texts in the database? Then:
$text = md5($text);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question