Unique Text in MySQL Database Text Field

Posted by Guest memeber “Dipon”
MySQL Database, Text Field index can’t be selected as Unique. So checking duplicate data insert on text flied, its make resource usage high. For prevent duplicate data insert in text and reduce database usage, also the resource, I have to find alternative solution.

Its so easy. I add a extra field on database like name hash make it VARCHAR (255) and Index give unique. I covert all text in md5(“Your String”) and insert in hash field and original string on text field.
Below is example.

CREATE TABLE `post` (
...................................,
......................................,
`post_data` text NOT NULL,
`hash` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `hash` (`hash`)
);

Insert SQL:
INSERT INTO `post` ( ............, ..........., `post_data`, ..........., `hash`) VALUES ( NULL , ............, ............, 'Test Text', ............, 'e0adbcccc2055d976bfe3d6113c2f1d4', );

Posted by Guest memeber “Dipon”. He is a web application architect. He loves to develop php and mySql base web applications.

Incoming search terms:

  • mysql automatic unqiue text (1)
You can leave a response, or trackback from your own site.

One Response to “Unique Text in MySQL Database Text Field”

Leave a Reply

Powered by WordPress | Designed by: best suv | Thanks to trucks, infiniti suv and toyota suv