I am attempting to create a python script that connects to an MS SQL Studio database and using SQLAlchemy to help with this. (I am learning databases and python), but I am trying to create a connection to a new database but keep getting this "create_engine" is not defined in SQLAlchemy error.
from sqlalchemy import create_engine
import pyodbc
import pandas as pd
SERVER = 'BEAST-ACTIVE\SQLEXPRESS' #FIND SERVER NAME
DATABASE = 'SQLTUTORIAL' #DATABASE TO CONNECT TO
DRIVER = 'SQL Server' #FIND DRIVER
USERNAME = 'abcd'
PASSWORD = 'abcd123'
DATABASE_CONNECTION = f'msql://{USERNAME}:{PASSWORD}@{SERVER}/{DATABASE}?driver={DRIVER}'
engine = create_engine(DATABASE_CONNECTION)
connection = engine.connect()
data = pd.read_sql_query("SELECT * from
[SQLTUTORIAL].[dbo].[EmployeeDemographics]
order by [EmployeeID]", connection)
data.dtypese
OUTPUT:
NameError
Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 engine =
create_engine(DATABASE_CONNECTION)
2 connection = engine.connect()
3 data = pd.read_sql_query("SELECT *
from [SQLTUTORIAL].[dbo].
[EmployeeDemographics] order by
[EmployeeID]", connection)
NameError: name 'create_engine' is not defined
I am using Anaconda Jupyter Notebook 6.4.8 and MSSQLMS 18.12.1