2014-09-25 56 views
0

我想创建很多sql表? 我想这一点,〔实施例:如何在python中使用for循环创建表(sql)?

import sqlite3 
conn = sqlite3.connect(":memory:") 
c = conn.cursor() 
for x in range(0, 100): 
    c.execute('''CREATE TABLE tableX (id real, name text,price real)''') 

X在范围内: X: 0,1,.....,100

+0

你可以做到这一点,但它看起来像一个错误的数据库设计。如果你开始编号你的变量或表,你做错了什么。 – Matthias 2014-09-25 12:26:19

回答

1
import sqlite3 
conn = sqlite3.connect(":memory:") 
c = conn.cursor() 
for x in range(0, 100): 
    c.execute('''CREATE TABLE table%s (id real, name text,price real)'''%x)