4つのテーブルを作成し、IDを使用してそれらをリンクしました。IDとして何を使用するかをどのように決定しますか?
テーブルの作成
import sqlite3 as lite
queries = []
queries.append([''.join('CREATE TABLE Movie',
'(id INTEGER PRIMARY KEY,',
'title INTEGER,',
'genre INTEGER,',
'cost INTEGER)')])
queries.append([''.join('CREATE TABLE Title',
'(id INTEGER,',
'English TEXT,',
'Spansih TEXT,',
'French TEXT)')])
queries.append([''.join('CREATE TABLE Genre',
'(id INTEGER,',
'Action INTEGER,',
'Comedy INTEGER,',
'Drama INTEGER',
'Romance INTEGER)')])
queries.append([''.join('CREATE TABLE Cost',
'(id INTEGER,',
'Base INTEGER,',
'Shipping INTEGER,',
'Total INTEGER)')])
行を追加する
title_id = None # How do i determines these?
genre_id = None # Should I just use Integer Primary Key for each table id?
cost_id = None # But then how do I get those id values to put into
queries.append('''INSERT INTO Movies
(title, genre, cost) VALUES(%d, %d, %d)''' %
(titile_id, genre_id, cost_id))
queries.append('''INSERT INTO Title
(id, English) VALUES(%d, %s)''' %
(title_id, 'Movie 1'))
queries.append('''INSERT INTO Genre
(id, Action, Comedy) VALUES(%d, %d. %d)''' %
(genre_id, 1, 1,))
queries.append('''INSERT INTO Cost
(id, Base, Shipping, Total) VALUES(%d, %d, %d, %d)''' %
(cost_id, 50, 8, 58))
for q in queries:
print q