Link to home
Start Free TrialLog in
Avatar of MNCW2
MNCW2

asked on

check duplicate before insert

given table

      table Directory
-------------------------
Id            auto increment
Name       varchar(10)
Hp            varchar(12)

I need to insert around few hundreds of records in this table. But I had to make sure
'Hp' which doesn't duplicate. It means I need to check if the record exist in table which same with the record
that I want to insert. Any suggestion? Create indexes would slow insertion query. I am code in php,please help.
ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of waygood
waygood

Change HP to UNIQUE in the database structure, and do @mysql_query, as duplicates will throw an error.

OR

Use REPLACE instead of INSERT, assuming 'name' will be the same for any matching HP value