Python 如何确定arn';t使用自动增量
我已经创建了4个表,并使用ID将它们链接在一起。现在我如何确定使用什么作为ID 表格创建Python 如何确定arn';t使用自动增量,python,database,sqlite,identity,Python,Database,Sqlite,Identity,我已经创建了4个表,并使用ID将它们链接在一起。现在我如何确定使用什么作为ID 表格创建 import sqlite3 as lite queries = [] queries.append([''.join('CREATE TABLE Movie', '(id INTEGER PRIMARY KEY,', 'title INTEGER,', 'genre INTEGER,', 'cost INT
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
每个表的id
应该是INTEGER主键
title_id = None # How do i determines these?
cost_id = None # But then how do I get those id values to put into
在电影之前插入标题和成本。省略手动设置id(即,改为将do插入成本(基本、装运、总计)值(…,…,…)
)。运行插入后,立即使用游标.lastrowid获取最新的自动生成id
title_id = None # How do i determines these?
cost_id = None # But then how do I get those id values to put into