title: How to speed up bulk insert to MS SQL Server using pyodbc
body: <p>Below is my code that I'd like some help with.
  I am having to run it over 1,300,000 rows meaning it takes up to <em>40 minutes</em> to insert ~300,000 rows. </p>
  
  <p>I figure bulk insert is the route to go to speed it up? 
  Or is it because I'm iterating over the rows via <code>for data in reader:</code> portion?</p>
  
  <pre><code>#Opens the prepped csv file
  with open (os.path.join(newpath,outfile), 'r') as f:
      #hooks csv reader to file
      reader = csv.reader(f)
      #pulls out the columns (which match the SQL table)
      columns = next(reader)
      #trims any extra spaces
      columns = [x.strip(' ') for x in columns]
      #starts SQL statement
      query = 'bulk insert into SpikeData123({0}) values ({1})'
      #puts column names in SQL query 'query'
      query = query.format(','.join(columns), ','.join('?' * len(columns)))
  
      print 'Query is: %s' % query
      #starts curser from cnxn (which works)
      cursor = cnxn.cursor()
      #uploads everything by row
      for data in reader:
          cursor.execute(query, data)
          cursor.commit()
  </code></pre>
  
  <p>I am dynamically picking my column headers on purpose (as I would like to create the most pythonic code possible).</p>
  
  <p>SpikeData123 is the table name.</p>