Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate entry check

Tags:

mysql

I'm trying to understand how MSQL's Duplicate Entry works.

What I do understand is when saving

title='aaaaaccccc'

twice and the title field is unique you will get the error: Duplicate entry.

Does MySQL truncates a string with length = 200 to 64 chars and then check if the 64 chars long string is unique?

UPDATE:

When I save 2 records (titles) MySQL complains about violation of a unique constraint when saving the second title. The titles are the same for the first, lets say, 100 chars. After that it differs. Wy does MySQL throws a duplicate key error anyway.

like image 572
nelsonvarela Avatar asked Aug 11 '26 16:08

nelsonvarela


1 Answers

It depends on the data type: varchar columns will be trimmed, but char columns not (they are padded out to the specified column length).

like image 73
davek Avatar answered Aug 13 '26 06:08

davek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!