簡體   English   中英

創建一個具有變量名的表(sqlite3)

[英]create a table with variable name (sqlite3)

我想在sqlite3中使用python創建一個表,當我將number1更改為變量名時,將表名更改為變量名,將表名更改為表名,而不是變量中的值

db.execute("create table if not exists number1 (ID integer primary key autoincrement, item text, quantity integer,price_per_once integer, total integer)")

提前致謝

連接一個變量:

db.execute("create table if not exists " + table_name + " (ID integer primary key autoincrement, item text, quantity integer,price_per_once integer, total integer)")

盡管如果要使用相同的結構創建許多表,則可能有更好的方法來設計架構。 無論所有這些表之間有什么區別,它都可能只是表中的一列。

您是否嘗試過以下方法:

db.execute("create table " + tableNameVariable + " (...)")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM