2
で既存のテーブルに自動インクリメントID列を追加し、私は以前に何のIDを持っていた既存のテーブルに自動インクリメントID列を追加したい:SqliteをSQLiteにも使用
import sqlite3
db = sqlite3.connect(':memory:')
c = db.cursor()
c.execute('create table events (int weight, text str)')
c.execute('insert into events values(?, ?)', (1371, 'Test1'))
c.execute('insert into events values(?, ?)', (223, 'Test2'))
c.execute('select * from events'); print c.fetchall()
# [(1371, u'Test1'), (223, u'Test2')]
# add an autoincrementing ID to existing table
c.execute('alter table events add id int not null auto_increment primary key')
それを正しく行う方法?私はこのエラーを持っている:それは作成された後
sqlite3.OperationalError: near "auto_increment": syntax error
大量の行(> 1 mln)のテーブルがキャッシュを取り除くために「VACUUM」ステートメントを使用する場合。 –