I am trying to insert 2,000,000 records from a .CSV
file into Microsoft SQL Server using Python. Standard insert function took me 3 hours to upload all records. I am trying to reduce this to minutes.
I am fairly new to Python.
import pyodbc
import csv
import time
import pandas as pd
new_data = []
t0 = time.time()
conn = pyodbc.connect('Driver={SQL Server};'
'Server=xyz;'
'Database=Rst;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
cursor.fast_executemany = True
parameter = [()]
with open(r"\\abc.csv") as csvDataFile:
csvReader = csv.reader(csvDataFile)
next(csvReader)
for row in csvReader:
cursor.executemany('INSERT INTO [dbo].[Science_Catalogue_Extraction]([Supplier],[Catalogue_Number],[Description],[Long_Description],[UNSPSC_Code],[CAS_Number],[Victoria_Hazard_Flag],[Overall_Status],[Chemical_Buyers_Override],[Standard_Buyers_Override])''VALUES(?,?,?,?,?,?,?,?,?,?)',row)
print(f'{time.time() - t0:.1f} seconds')
conn.commit()
cursor.close()
conn.close()`
I am getting an error
TypeError: ('Params must be in a list, tuple, or Row', 'HY000').
Please help :(