Conteúdo do Curso
SQL in Python Projects
SQL in Python Projects
Connect and cursor
Connect to DB
Before creating a table, you need to:
- Import the library;
- Connect or create a database;
Establish a connection to the database (or create a new one if it doesn't exist) where 'my_database.db'
is the database name.
- Create a cursor;
Create a cursor for executing SQL queries.
A cursor
is a tool for working with data in a database, like a virtual pointer to access and manage information.
The cursor
is an object that allows you to interact with the database and execute SQL queries. The cursor
defines which part of the database you are currently interacting with.
After running the code, you will have access to the "my_database.db"
database and a ready-to-use cursor
for executing SQL queries. If the database didn't exist previously, it will be created upon running this code.
my_database.db
in the project folder is the database file.
In the next section, we will create the first table.
Obrigado pelo seu feedback!