i'm facing an issue when i'm trying to insert records in a table with similar columns. So basically my table is structured like this ::
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | YES | MUL | NULL | |
+-------+-------------+------+-----+---------+----------------+
Now my PDO statement is this::
INSERT INTO supplement_brand (name) VALUES (:name)
So basically what i want is, that each name field will have a unique value. I already have INDEX set on the name field. Now i wanted to remove the primary key, and the auto-increment attributes from the id field. But that would entail bad database design practices.
Right now upon insertion the id field is being auto-incremented automatically, and many duplicate values are getting inserted in the name field:
Here is a sample of whats happening ::
+-----+-----------------------------+
| id | name |
+-----+-----------------------------+
| 1 | 2 to 1 Protein Bar |
| 7 | 2 to 1 Protein Bar |
| 8 | 2 to 1 Protein Bar |
| 28 | 2 to 1 Protein Bar |
| 93 | 2 to 1 Protein Bar |
| 98 | 2 to 1 Protein Bar |
| 230 | 2 to 1 Protein Bar |
| 231 | 2 to 1 Protein Bar |
| 232 | 2 to 1 Protein Bar |
| 2 | 360CUT |
| 3 | 360CUT |
| 4 | 360CUT |
| 5 | 360CUT |
| 6 | 360CUT |
| 9 | 4 Dimension Nutrition |
| 10 | 4 Dimension Nutrition |
| 11 | 4 Dimension Nutrition |
| 12 | 4 Dimension Nutrition |
| 13 | 4 Dimension Nutrition |
| 14 | 4 Dimension Nutrition |
| 15 | 4 Dimension Nutrition |
| 16 | 4 Dimension Nutrition |
| 17 | 4 Dimension Nutrition |
| 18 | 4 Dimension Nutrition |
| 19 | 4 Dimension Nutrition |
| 20 | 4 Dimension Nutrition |
| 21 | 4 Dimension Nutrition |
| 22 | 4 Dimension Nutrition |
| 23 | 4 Dimension Nutrition |
| 24 | 4 Dimension Nutrition |
| 25 | 4 Dimension Nutrition |
+-----+-----------------------------+
How can i prevent the insertion of duplicate values in the name field. Please provide any sort of help, i'm literally stuck right now. Thanks in advance