Conteúdo do Curso
SQL in Python Projects
SQL in Python Projects
1. Development Environment on Your PC
2. Introduction to SQLite
4. More About SQLite
Challenge 1: First table
Complete all parts of the task in sequence
- 📁 Create a new project in PyCharm;
- 📝 Create a new python file;
- 📚 Import the
sqlite3
library; - 🗄 Create a new database;
- 🤚 Create a
cursor
; - 📄 Create a table named
articles
with the following fields:
- 🪖 Save the changes;
- 🔑 Close the database connection.
1. It is recommended to do ...
2. Some text
3. Use such method.
2. Some text
It is how code looks like
text again3. Use such method.
# Import the sqlite3 library
import sqlite3
# Create a new database (or connect to an existing one)
connection = sqlite3.connect("my_database.db")
# Create a cursor
cursor = connection.cursor()
# Create a table named "articles" with the specified fields
cursor.execute('''
CREATE TABLE articles (
id INTEGER,
title TEXT,
content TEXT,
author TEXT
)
''')
# Save the changes and close the database connection
connection.commit()
connection.close()
Tudo estava claro?
Seção 2. Capítulo 5
Conteúdo do Curso
SQL in Python Projects
SQL in Python Projects
1. Development Environment on Your PC
2. Introduction to SQLite
4. More About SQLite
Challenge 1: First table
Complete all parts of the task in sequence
- 📁 Create a new project in PyCharm;
- 📝 Create a new python file;
- 📚 Import the
sqlite3
library; - 🗄 Create a new database;
- 🤚 Create a
cursor
; - 📄 Create a table named
articles
with the following fields:
- 🪖 Save the changes;
- 🔑 Close the database connection.
1. It is recommended to do ...
2. Some text
3. Use such method.
2. Some text
It is how code looks like
text again3. Use such method.
# Import the sqlite3 library
import sqlite3
# Create a new database (or connect to an existing one)
connection = sqlite3.connect("my_database.db")
# Create a cursor
cursor = connection.cursor()
# Create a table named "articles" with the specified fields
cursor.execute('''
CREATE TABLE articles (
id INTEGER,
title TEXT,
content TEXT,
author TEXT
)
''')
# Save the changes and close the database connection
connection.commit()
connection.close()
Tudo estava claro?
Seção 2. Capítulo 5