BaşlayınÜcretsiz Başlayın

Create the table to the database

Having setup the engine and initialized the metadata, you will now define the census table object and then create it in the database using the metadata and engine from the previous exercise. To create it in the database, you will have to use the .create_all() method on the metadata with engine as the argument.

It may help to refer back to the Chapter 4 exercise in which you learned how to create a table.

Bu egzersiz

Introduction to Databases in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Import Table, Column, String, and Integer from sqlalchemy.
  • Define a census table with the following columns:
    • 'state' - String - length of 30
    • 'sex' - String - length of 1
    • 'age' - Integer
    • 'pop2000' - Integer
    • 'pop2008' - Integer
  • Create the table in the database using the metadata and engine.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Import Table, Column, String, and Integer


# Build a census table: census
census = Table('census', metadata,
               Column('state', ____),
               Column(____, ____),
               ____,
               ____,
               ____)

# Create the table in the database
____
Kodu Düzenle ve Çalıştır