Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Table Design | More About SQLite
Databases in Python

book
Challenge: Table Design

Завдання

Swipe to start coding

You need to complete the code to create a table in an SQLite database named cars. The table should contain four fields:

  1. id — a unique identifier for the car.
  2. brand — the brand of the car.
  3. engine_capacity — the engine capacity of the car.
  4. video_presentation — a video presentation of the car.

Fill in the blanks in the SQL query by choosing the correct data types for each field.

Рішення

import sqlite3

conn = sqlite3.connect("cars_info.db")
cursor = conn.cursor()
# Create a table named `cars` with the specified fields and data types
cursor.execute('''
CREATE TABLE IF NOT EXISTS cars (
id INTEGER PRIMARY KEY,
brand TEXT,
engine_capacity REAL,
video_presentation BLOB
)
''')
conn.commit() # save the changes
conn.close() # close the database connection

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 3
import sqlite3

conn = sqlite3.connect("cars_info.db")
cursor = conn.cursor()
# Create a table named `cars` with the specified fields and data types
cursor.execute('''
CREATE TABLE IF NOT EXISTS cars (
id ___,
brand ___,
engine_capacity ___,
video_presentation ___
)
''')
conn.commit() # save the changes
conn.close() # close the database connection
toggle bottom row
some-alt