• Tutorial

    How to avoid duplicates when you insert hundreds of thousands of entries into the same MySQL table

    let’s assume that you are working on an application that requires all entries on a table (lets call it entries) to be unique. If we are writing our application with PHP/Laravel the migration (more precisely its up() method) of the table would look like this: public function up() { Schema::create('entries', function (Blueprint $table) { $table->increments('id'); $table->string('parameters_001')->nullable(); $table->string('parameters_002')->nullable(); $table->string('parameters_003')->nullable(); $table->string('parameters_004')->nullable(); $table->timestamps(); }); } One way to solve this issue (if not the most obvious one that comes to mind) is the following: use a simple check, create a method called isDuplicated($entry) that searches for the entry in the table, if it doesn’t exist insert it, otherwise, throw an exception. This method…