conn.execute('''CREATE TABLE COMPANY (ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL);''') print"Table created successfully";
conn = sqlite3.connect('test.db') for i inrange(1,9): t = 'list' + str(i) conn.execute("INSERT INTO NEW2 (ID,NAME) \ VALUES (NULL, ?)",(t,))
conn.commit() conn.close()
运行结果为数据库添加了一下数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
ID = 1 NAME = list1 ID = 2 NAME = list2 ID = 3 NAME = list3 ID = 4 NAME = list4 ID = 5 NAME = list5 ID = 6 NAME = list6 ID = 7 NAME = list7 ID = 8 NAME = list8