title: How to correctly use Laravel with SQL Server instead on MySQL?
body: <p>I am trying to use SQL Server for my databases with my Laravel project. I was able to connect SQL Server with Laravel 5.2. However, when I try to seed data into the table I get this error</p>
  
  <pre><code>[Illuminate\Database\QueryException] SQLSTATE[23000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Cann ot insert explicit value for identity column in table 'surveys' when IDENTITY_INSERT is set to OFF. (SQL: insert into [surveys] ([id], [name]) values (10, 'Some Text'))
  </code></pre>
  
  <blockquote>
    <p>Note: I am trying to supply the identity value which is probably what is causing the problem. </p>
  </blockquote>
  
  <p>While researching the SQL error, I learned that I need to execute the following queries.</p>
  
  <p>Before seeding I need to execute</p>
  
  <pre><code>SET IDENTITY_INSERT surveys ON;
  </code></pre>
  
  <p>After the seeding I need to execute</p>
  
  <pre><code>SET IDENTITY_INSERT surveys OFF;
  </code></pre>
  
  <p>But I am not sure how can I execute these command using Laravel</p>
  
  <p>How can I seed while supplying the value for the identity column without this issue?</p>
  
  <p>UPDATED
  Here is my seeder</p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Seeder;
  
  class FinalSurveyTS extends Seeder
  {
      /**
       * Run the database seeds.
       *
       * @return void
       */
      public function run()
      {   
          $myTable = 'surveys';
  
          DB::statement('SET IDENTITY_INSERT ' . $myTable . ' ON');
  
  
          DB::table($myTable)-&gt;truncate();
  
  
          DB::table($myTable)-&gt;insert([
              'id' =&gt; 10,
              'name' =&gt; 'some name',
          ]);
  
          DB::statement('SET IDENTITY_INSERT ' . $myTable . ' OFF');
      }
  }
  </code></pre>