# ODBC setup for KDB+ to query other databases

**URL:** https://forum.kx.com/t/odbc-setup-for-kdb-to-query-other-databases/13378
**Category:** Community Support
**Tags:** kdb-and-q, imported
**Created:** [March 15, 2023, 12:00am UTC](https://forum.kx.com/t/odbc-setup-for-kdb-to-query-other-databases/13378 "2023-03-15T00:00:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![darrenwsun](https://avatars.discourse-cdn.com/v4/letter/d/7ab992/32.png) [@darrenwsun](https://forum.kx.com/u/darrenwsun)
#### Post date: [March 15, 2023, 12:00am UTC](https://forum.kx.com/t/odbc-setup-for-kdb-to-query-other-databases/13378/1 "2023-03-15T00:00:00Z")

</div>

[https://learninghub.kx.com/forums/topic/odbc-setup-for-kdb-to-query-other-databases](https://learninghub.kx.com/forums/topic/odbc-setup-for-kdb-to-query-other-databases)

Hi community,

There used to be [this link](https://code.kx.com/q/interfaces/q-client-for-odbc/") that provides the instructions for the setup, but it’s no longer valid and I cannot find out the updated link anywhere. Note that it’s for the reverse direction of querying KDB+ via ODBC where the setup is easily found.

Thanks for the help.

---

<div class="post-metadata">

### Author: ![rocuinneagain](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/rocuinneagain/32/287_2.png) [@rocuinneagain](https://forum.kx.com/u/rocuinneagain)
#### Post date: [March 15, 2023, 12:00am UTC](https://forum.kx.com/t/odbc-setup-for-kdb-to-query-other-databases/13378/2 "2023-03-15T00:00:00Z")

</div>

ODBC:

- [kdb/odbc.pdf at master johnanthonyludlow/kdb GitHub](https://github.com/johnanthonyludlow/kdb/blob/master/docs/odbc.pdf")
- [kdb/odbc.txt at master KxSystems/kdb GitHub](https://github.com/KxSystems/kdb/blob/master/c/odbc.txt")
- [kdb/odbc.k at master KxSystems/kdb GitHub](https://github.com/KxSystems/kdb/blob/master/c/odbc.k")

JDBC:
- [GitHub - CharlesSkelton/babel: Babel for kdb+ / Query any database from kdb+ via jdbc](https://github.com/CharlesSkelton/babel")

&nbsp;

[EmbedPy](https://code.kx.com/platform/embedpy/") is also an option which has a lot of flexibility.

Some example of Pandas/PyODBC/SQLAlchemy usage below

&nbsp;

```
// https://github.com/KxSystems/embedPy 
system"\l p.q"; 
// https://github.com/KxSystems/ml 
system"\l ml/ml.q"; 
.ml.loadfile`:init.q; 
odbc:.p.import[`pyodbc]; 
pd:.p.import[`pandas]; 
connectString:";" 
sv {string[x],"=",y}(.)/:( (`Driver;"{ODBC Driver 17 for SQL Server}"); (`Server;"server.domain.com\DB01"); (`Database;"Data"); (`UID;"KX"); (`PWD;"password") ); 
connSqlServer:odbc[`:connect][connectString]; 
data:.ml.df2tab pd[`:read_sql]["SELECT * FROM tableName";connSqlServer]; 
cursor:connSqlServer[`:cursor][]; 
cursor[`:execute]["TRUNCATE FROM tableName"]; 
connSqlServer[`:commit][]; 
sa:.p.import`sqlalchemy; 
engine:sa[`:create_engine]["mssql+pyodbc://KX:password@server.domain.com\DB01/Data?driver=ODBC+Driver+17+for+SQL+Server"]; 
df:.ml.tab2df[data]; //Data to publish 
df[`:to_sql]["tableName";engine; `if_exists pykw `append;`index pykw 0b];
```

&nbsp;

&nbsp;
