Skip to content
Advertisement

Python SQL script inserts only the last row of the dataframe to SQL Server [pyodbc]

I am trying to import a pandas dataframe to Microsoft SQL Server. Even though, the command is correct and executed successfully, when I select the first 1000 rows of the table in SQL server only the last row of the imported dataframe is shown.

I have the latest version of SQL Server (downloaded yesterday)

Do you know what’s causing this?

SQL Code (Stored procedure)

Python script to import the data

Dataframe I want to import

enter image description here

SQL Result

enter image description here

Advertisement

Answer

I select the first 1000 rows of the table in SQL server only the last row of the imported dataframe is shown.

Because your stored procedure drops the table every time before inserting a row.

So don’t do that. Also don’t use @ in your column names. That’s just for parameters, arguments, and local variables.

EG:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement