Tuesday, March 7, 2017

Make a MySQL database always start auto_increment at 1000

Using MySQL or PHP (in Laravel), is it possible to automatically set auto_increment to 1000 anytime a new table is created?

To be clear, I know I can call ALTER TABLE member AUTO_INCREMENT = 1000; to do this after creating a table and that I can incorporate in the code to create the table. Im looking for a way to have this happen automatically.

To elaborate, I use laravel and in my database migrations I currently do this:

  Schema::create('member', function (Blueprint $table){
        $table->increments('id');
        // ... 
  });
  DB::update("ALTER TABLE member AUTO_INCREMENT = 1000;");

I'm wondering if it is possible to script it somehow through MySQL or PHP so that something equivalent to DB::update("ALTER TABLE member AUTO_INCREMENT = 1000;"); anytime I create a table



via DelightedD0D

Advertisement