Skip to content
Advertisement

How can I access a SQL file while using python?

Right now I’m using Microsoft SQL Community to start a database, but for some reason I can’t command the server to do something that I want, is there any to use the library sqlite3 or pyodc to print a value that I want on the console?

PYTHON:

JavaScript

SQL:

JavaScript

Advertisement

Answer

sqlite3 talks to SQLite databases.

If you want to talk to a Microsoft SQL Server, Microsoft recommends using pyodbc. Follow the instructions to connect and run queries and the pyodbc documentation. To execute queries from a file, read the contents of the file and run it like any other query.

Note that executescript is specific to sqlite3. Use execute.

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