I have song
table which has songCategory
and songName
columns. The combination of songCategory
and songName
is set to unique in database level. So basically even if php tries to insert duplicate entries database will not allow.
The problem is, project has functionality where user can insert bunch of songs at once. And as you know, duplicate record check for big data takes very long: For each song I must query if there is any song with categoryID=x
and songName=y
. So I need your suggestions to solve this problem without extra duplicate check.
I have few ideas about this but I'm not quite sure if they will work:
- We can insert records anyway, if there will be database error, we simply
continue
foreach loop. - We can trigger some function in database to check and delete duplicate rows after each insert (I have no experience with custom mysql functions)
Btw, I'm using Yii Framework with MySQL database.
Your suggestions?