Using Python's pyodbc module to connect to Microsoft SQL Server and import data into SSMS.
This mini project offers an alternative method to importing data into SSMS compared to the process shown in "Alex The Analyst's" Data Analyst Portfolio Project | SQL Data Exploration | Project 1/4 video.
Link to his video
-
Initially, I was unable to import the data into SSMS directly from Excel as a data source.
-
Instead, I utilized the pyodbc package in Python to create my tables, which allowed me to insert my data afterward.
-
You'll notice that I had to use the
fillna()function in order to convert them to an acceptableNULLvalue for SSMS. -
The benefit of doing this is that it avoids the need for us to use a
CAST()or any type ofCONVERT()to an int datatype because the tables created initially are of float datatypes.
Note: While I fully agree that I could have simply imported a flat file source in SSMS, I opted to explore something different, hence my use of pyodbc as an alternative. ![]()
SQL ServerSSMSODBC Driver For SQL ServerVSCodePyODBC modulepandasnumpy
- Configure SQL Server and ensure you have an ODBC Driver setup already.
- pip install the
pyodbc,pandas,numpymodule in VSCode's terminal. - Use the code.