In [5]:
%load_ext sql
The sql extension is already loaded. To reload it, use:
  %reload_ext sql
In [6]:
%sql mssql+pyodbc:///?odbc_connect=DRIVER%3DODBC+Driver+17+for+SQL+Server%3BSERVER%3D.%5CSQLEXPRESS%3BDATABASE%3DAdventureWorks%3BUID%3Dmike%3BPWD%3Dpassword
Out[6]:
'Connected: @'
In [9]:
res = %sql SELECT TOP 10 * FROM FactProductInventory
 * mssql+pyodbc:///?odbc_connect=DRIVER=ODBC Driver 17 for SQL Server;SERVER=.\SQLEXPRESS;DATABASE=AdventureWorks;UID=mike;PWD=password
Done.
In [10]:
res
Out[10]:
ProductKey DateKey MovementDate UnitCost UnitsIn UnitsOut UnitsBalance
1 20101228 2010-12-28 0.3200 0 0 875
1 20101229 2010-12-29 0.3200 0 0 875
1 20101230 2010-12-30 0.3200 0 0 875
1 20101231 2010-12-31 0.3200 0 0 875
1 20110101 2011-01-01 0.3200 0 0 875
1 20110102 2011-01-02 0.3200 0 0 875
1 20110103 2011-01-03 0.3200 0 0 875
1 20110104 2011-01-04 0.3200 0 0 875
1 20110105 2011-01-05 0.3200 0 0 875
1 20110106 2011-01-06 0.3200 0 0 875
In [ ]: