How to Execute SQL from a File on SqLite Using Python

Поделиться
HTML-код
  • Опубликовано: 25 фев 2022
  • Let's go back to our look at SqLite, a fantastic, high performance file database that can be embedded with apps and handle all kinds of data operations when no data server is available. Like all RDBMS systems, SqLite can take a SQL file that is full of statements and execute them all. This allows you to build your SQL in your favorite editor, just as you would do for other databases, then run it just by specifying the filename in your script. Join me as we introduce executescript on sqlite3 using Python.
    Related Videos:
    Getting Started with SQLite for Python
    • Getting Started with S...
    How to Execute SQL from a File on SqLite Using Python
    You are watching this video now!
    How to Select Data from SQLite
    • How to Select Data fro...
    How to Output HTML from SQLite
    • How to Output HTML fro...
    Migrate Data from MS Excel to SQLite and Back Again
    • Migrate Data from MS E...
    How to Use Dates in SQLite
    • How to Use Dates in SQ...
    How to Create a Delimited Field in your SQLite Query with Python
    • How to Create a Delimi...
    How to Make an Interactive Map Using Python and SQLite Data
    • How to Make an Interac...
    For developers looking for a new role, check out and sign up:
    www.toptal.com/qKaO2b/worlds-...
    Needing to hire technical resources for your project? Get the best:
    www.toptal.com/qKaO2b/worlds-...
    Want to get access to premium content made just for you and have a chat with me? Find me on Patreon :
    / mackenziedataengineering
    Want to work with me 1:1? Contact me today and book your free 20 min consultation!
    Contact form you can find at www.mackenziemackenzie.com/
    Follow me on social media:
    / mackenziedataanalytics
    / seamacke
    / seamacke
    / seamacke
    / psmackenzie
    Get Microsoft Office including Access:
    click.linksynergy.com/fs-bin/...
    Got a RUclips Channel? I use TubeBuddy, it is awesome. Give it a try:
    www.tubebuddy.com/seanmackenz...
    #sqlite #sqlite3 #python
  • НаукаНаука

Комментарии • 10

  • @lucatoni1481
    @lucatoni1481 Год назад +1

    Just what I was looking for! Thank you!!

  • @lucillewiid5476
    @lucillewiid5476 11 месяцев назад +1

    Hi Sean can you maybe show/make a video of how you read the .sql script in sqlite3, but with a function and then add, remove and update information in your database?

  • @uncleiroh3616
    @uncleiroh3616 2 года назад +2

    Great video. I have a few questions though.
    1)Can you import * from the sqlite3 module and if so, isn't that better to do?
    2)Why did you import a seperate function from sqlite3 if the whole module was imported in the first place?
    3)On line 6, on the filename variable, What does 'r' do exactly? I've noticed that it covers the backslashes but what's the definition of it?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 года назад +1

      Good questions! 1. Yes you can use import *, or just import sqlite3 and it will run fine 2. I imported Error separately to show what we're trying to catch in our except: block, but it is not necessary to import separately. 3. r in the open function specifies "read only"

    • @Slangs
      @Slangs Год назад

      This is pretty late but 3) the r is for raw, it just takes everything between quotes as is and ignores all expressions such as
      or \ or \t and prints them out

    • @PedroAndrade19
      @PedroAndrade19 Год назад

      Its not a good practice to import anything using * . Imagine that you have tu packages and they have a method with the same name.

  • @sandhyas5869
    @sandhyas5869 Год назад +1

    Good Video,I have a question too.
    How to execute multi SQL statements from a sql file with psycopg2 using python