How to write a query so that there are no repetitions in the column?

For example, if you add a query with the value Vladimir in the Name column, it was not added if there is already an entry Vladimir in the column)

In SQLite, I just create a structure that prevents the addition, but in MySQL I do not know ...

1 answer 1

Suppose there is a table tbl with a text field name in which there must be only unique values. For this, it is most convenient to use a unique index, which can be added to the table either by using the query

 CREATE UNIQUE INDEX index_of_name ON tbl (name(10)); 

either with the ALTER TABLE statement

 ALTER TABLE tbl ADD UNIQUE INDEX index_of_name (name(10)); 

After that add a duplicate value in the table will not work. If you do not want to receive error messages when you try to insert a duplicate value, you can use the IGNORE keyword in the INSERT .